Skip to content

Instantly share code, notes, and snippets.

@menugget
Last active July 10, 2016 18:03
Show Gist options
  • Save menugget/7516921 to your computer and use it in GitHub Desktop.
Save menugget/7516921 to your computer and use it in GitHub Desktop.
[R function] "new.range" - Scale data to a new range. Arguments include the data, the new minimum, and the new maximum values.
new.range <- function(x, new.min=0, new.max=1){
ranx <- range(x, na.rm=TRUE)
px <- (x-ranx[1])/(ranx[2]-ranx[1])
res <- new.min+((new.max-new.min)*px)
res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment