Created
June 25, 2014 22:19
-
-
Save mprymek/e257abc5e39afe01d928 to your computer and use it in GitHub Desktop.
R - set values in vector to the nearest value from the given boundaries vector
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
to_nearest = function(d,bounds) { | |
lapply(d,FUN=function(x){ | |
idx=which.min(abs(bounds-x)) | |
bounds[idx] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment