Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread William Dunlap
wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Andras Farkas > Sent: Tuesday, June 18, 2013 10:24 AM > To: Bert Gunter > Cc: R mailing list > Subject: Re: [R] find closest value in a

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Andras Farkas
ter > Subject: Re: [R] find closest value in a vector based on another vector values > To: "Andras Farkas" > Cc: "Jorge I Velez" , "R mailing list" > > Date: Tuesday, June 18, 2013, 10:55 AM > Andras: > > No. > Using the a = c(1,8,9) and b = 2

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Bert Gunter
: > >> From: Bert Gunter >> Subject: Re: [R] find closest value in a vector based on another vector >> values >> To: "Jorge I Velez" >> Cc: "Andras Farkas" , "R mailing list" >> >> Date: Tuesday, June 18, 2013, 10:07

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Andras Farkas
ter > Subject: Re: [R] find closest value in a vector based on another vector values > To: "Jorge I Velez" > Cc: "Andras Farkas" , "R mailing list" > > Date: Tuesday, June 18, 2013, 10:07 AM > Jorge: No. > > > a <-c(1,5,8,15,32,3

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Jorge I Velez
T hank you very much, Bert. Point well taken. Regards, Jorge.- On Wed, Jun 19, 2013 at 12:07 AM, Bert Gunter wrote: > Jorge: No. > > > a <-c(1,5,8,15,32,33.5,69) > > b <-c(8.5,33) > > a[findInterval(b, a)] > [1] 8 32 ##should be 8 33.5 > > I believe it has to be done explicitly by finding

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Bert Gunter
Jorge: No. > a <-c(1,5,8,15,32,33.5,69) > b <-c(8.5,33) > a[findInterval(b, a)] [1] 8 32 ##should be 8 33.5 I believe it has to be done explicitly by finding all the differences and choosing those n with minimum values, depending on what n you want. Note that the problem is incompletely spe

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread arun
Hi, Perhaps this works: a[sapply(b,function(x) which.min(abs(x-a)))] #[1]  8 32 A.K. - Original Message - From: Andras Farkas To: r-help@r-project.org Cc: Sent: Tuesday, June 18, 2013 8:34 AM Subject: [R] find closest value in a vector based on another vector values Dear All, would

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Jorge I Velez
Dear Andras, Try > a[findInterval(b, a)] [1] 8 32 HTH, Jorge.- On Tue, Jun 18, 2013 at 10:34 PM, Andras Farkas wrote: > Dear All, > > would you please provide your thoughts on the following: > let us say I have: > > a <-c(1,5,8,15,32,69) > b <-c(8.5,33) > > and I would like to extract from

[R] find closest value in a vector based on another vector values

2013-06-18 Thread Andras Farkas
Dear All, would you please provide your thoughts on the following: let us say I have: a <-c(1,5,8,15,32,69) b <-c(8.5,33) and I would like to extract from "a" the two values that are closest to the values in "b", where the length of this vectors may change but b will allways be shorter than "a