Created
August 22, 2012 12:59
-
-
Save jlehtoma/3425358 to your computer and use it in GitHub Desktop.
Standardize value ranks between [0, 1]
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
# Based on: | |
# http://stackoverflow.com/questions/4401498/how-to-rank-values-in-a-vector-and-give-them-corresponding-values | |
# http://stackoverflow.com/questions/5468280/scale-a-series-between-two-points-in-r/5468527#5468527 | |
values <- runif(1000000) | |
# replace runif with getValues(raster) | |
ranks <- as.numeric(factor(values)) | |
# Transform variables to a scale between 0 and 1, while retaining rank order and | |
# the relative size of separation between values. | |
range01 <- function(x) { | |
return((x-min(x)) / (max(x) - min(x))) | |
} | |
stand.ranks <- range01(ranks) | |
# Check the difference between elements in stand.ranks | |
diff(sort(stand.ranks)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment