Created
October 7, 2015 14:33
-
-
Save swayson/b5a6d3cd796ab1d08df1 to your computer and use it in GitHub Desktop.
Min-max scaler in R
This file contains 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
minmax_scaler <- function(x, a, b) { | |
" | |
x: data. numeric vector of values to be scaled | |
a: desired minimum after scaling takes place | |
b: desired maximum after scaling takes place | |
e.g. f(c(1,2,3,4), 1, 17) | |
[1] 1.000000 6.333333 11.666667 17.000000 | |
" | |
(((b - a)*(x - min(x))) / (max(x) - min(x))) + a | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment