[R] check for nearest value in a vector

Martin Batholdy batholdy at googlemail.com
Wed Feb 8 13:56:02 CET 2012


Is there a way to check which value in a vector is nearest to a given value?

so for example I have vector x:

x <- c(1, 6, 12, 28, 33)

and I would like to get the position of the element of x that is nearest to 14
(in this case the third element).


More information about the R-help mailing list