Last active
June 1, 2019 23:49
-
-
Save shamilnabiyev/f5bf0a809d5288d980caf41134a1de4c to your computer and use it in GitHub Desktop.
Rescaling (min-max normalization) in R
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
age <- c(0, 2, 3, 5, 7, 10) | |
income <- c(0, 450, 900, 1200, 3000, 50000) | |
scale <- function(val, min_, max_) {val - min_}/(max_ - min_) | |
sapply(age, scale, min(age), max(age)) | |
# Output: 0.0 0.2 0.3 0.5 0.7 1.0 | |
sapply(income, scale, min(income), max(income)) | |
# Output: 0.000 0.009 0.018 0.024 0.060 1.000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment