Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add normalize() #143

Closed
jmbarbone opened this issue Sep 9, 2022 · 0 comments · Fixed by #145
Closed

Add normalize() #143

jmbarbone opened this issue Sep 9, 2022 · 0 comments · Fixed by #145
Labels
easier 🐇 Minimal work new feature 🎁 New feature request

Comments

@jmbarbone
Copy link
Owner

Something like

normalize <- function(
    x,
    range = range(na.rm = TRUE),
    bounds = 0:1
) {
  min <- range[1]
  max <- range[2]
  lower <- bounds[1]
  upper <- bounds[2]
  stopifnot(is.numeric(x), min < max, lower < upper)
  lower + (x - min) * (upper - lower) / (max - min)
}
@jmbarbone jmbarbone added easier 🐇 Minimal work new feature 🎁 New feature request labels Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easier 🐇 Minimal work new feature 🎁 New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant