Skip to content

Instantly share code, notes, and snippets.

@swayson
Created October 7, 2015 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swayson/b5a6d3cd796ab1d08df1 to your computer and use it in GitHub Desktop.
Save swayson/b5a6d3cd796ab1d08df1 to your computer and use it in GitHub Desktop.
Min-max scaler in R
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