View source: R/datalow_utils.r
which.closest | R Documentation |
which.closest finds either the number in a vector which is closest to the input value or its index value
which.closest(x, invect, index = T)
x |
the value to lookup |
invect |
the vector in which to lookup the value x |
index |
should the closest value be returned or its index; default=TRUE |
by default it returns the index in the vector of the value closest to the input value
vals <- rnorm(100,mean=5,sd=2)
pick <- which.closest(5.0,vals,index=TRUE)
pick
vals[pick]
vals[c(pick-5):(pick+5)]
which.closest(5.0,vals,index=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.