which.closest {MQMF} | R Documentation |
which.closest find a number in a vector closest to a given value
Description
which.closest finds either the number in a vector which is closest to the input value or its index value
Usage
which.closest(x, invect, index = TRUE)
Arguments
x |
the value to lookup |
invect |
the vector in which to lookup the value x |
index |
should the index be returned or the closest value; default=TRUE |
Value
by default it returns the index in the vector of the value closest to the input value x
Examples
vals <- rnorm(100,mean=5,sd=2)
pick <- which.closest(5.0,vals,index=TRUE) #closest to 5?
pick # the index of the closest
vals[pick] # its value
which.closest(5.0,vals,index=FALSE) # straight to the value
[Package MQMF version 0.1.5 Index]