Re: [R] check for nearest value in a vector

2012-02-08 Thread Martin Batholdy
great, thanks! On 08.02.2012, at 14:00, Dimitris Rizopoulos wrote: > How about this: > > x <- c(1, 6, 12, 28, 33) > > which.min(abs(x - 14)) > > > I hope it helps. > > Best, > Dimitris > > > On 2/8/2012 1:56 PM, Martin Batholdy wrote: >> Hi, >> >> Is there a way to check which value in a

Re: [R] check for nearest value in a vector

2012-02-08 Thread Petr PIKAL
Hi > > Hi, > > 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). Easy. Smallest

Re: [R] check for nearest value in a vector

2012-02-08 Thread Dimitris Rizopoulos
How about this: x <- c(1, 6, 12, 28, 33) which.min(abs(x - 14)) I hope it helps. Best, Dimitris On 2/8/2012 1:56 PM, Martin Batholdy wrote: Hi, 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 wou

[R] check for nearest value in a vector

2012-02-08 Thread Martin Batholdy
Hi, 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). thanks! __