Skip to content

Instantly share code, notes, and snippets.

@mprymek
Created June 25, 2014 22:19
Show Gist options
  • Save mprymek/e257abc5e39afe01d928 to your computer and use it in GitHub Desktop.
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
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