Last active
June 12, 2017 10:57
-
-
Save ashenkin/3f666de270dcb39d7a44dd9d1f76e5be to your computer and use it in GitHub Desktop.
A function to reverse the process of scale()'ing a vector 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
unscale <- function(scaled, scale, center) { | |
# provide either scale & center, or a scaled vector with the proper attributes | |
if (missing(scale) | missing(center)) { | |
stopifnot( c("scaled:center", "scaled:scale") %in% names(attributes(scaled)) ) | |
scale = attr(scaled, "scaled:scale") | |
center = attr(scaled, "scaled:center") | |
attr(scaled, "scaled:scale") <- NULL | |
attr(scaled, "scaled:center") <- NULL | |
} | |
unscaled = scaled * scale + center | |
return(unscaled) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment