Created
April 2, 2019 10:27
-
-
Save danlewer/49291896ebf12e6d7fca782805d37122 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rescale a numeric vector to new maximum and minimum values | |
# original values will map to new values in a linear fashion | |
rescale <- function(x, MIN, MAX) { # linear rescaling | |
y <- x - min(x) | |
y <- y * (MAX - MIN) / max(y) | |
y + MIN | |
} | |
# example | |
rescale(1:10, 0, 100) | |
rescale(1:10, 100, 0) # also works backwards |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment