Or perhaps something based on findInterval, like > d[findInterval(b, c(d,Inf))+1] [1] 12 36 36 The details depend on if your inequality is strict or not.
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of arun > Sent: Monday, June 17, 2013 11:58 AM > To: Andras Farkas > Cc: R help > Subject: Re: [R] vector question > > HI Andras, > Sorry, I misunderstood your question: > > Try this: > sapply(sapply(b,function(x) d[x<d]),`[`,1) > #[1] 12 36 36 > > > > > ----- Original Message ----- > From: Andras Farkas <motyoc...@yahoo.com> > To: arun <smartpink...@yahoo.com> > Cc: > Sent: Monday, June 17, 2013 2:48 PM > Subject: Re: [R] vector question > > Arun, > > thank you. Looking at it I am wondering if there is a way to get 36 in the > result instead of > the 24. The 2nd value in b is 24.6, therefore the 1st value greater then that > in d is 36. > > appreciate the help, > > Andras > > --- On Mon, 6/17/13, arun <smartpink...@yahoo.com> wrote: > > > From: arun <smartpink...@yahoo.com> > > Subject: Re: [R] vector question > > To: "Andras Farkas" <motyoc...@yahoo.com> > > Cc: "R help" <r-help@r-project.org> > > Date: Monday, June 17, 2013, 2:45 PM > > May be this helps: > > > > d[cumsum(sapply(d,function(x) any(x>b)))>=1] > > #[1] 12 24 36 > > A.K. > > > > > > ----- Original Message ----- > > From: Andras Farkas <motyoc...@yahoo.com> > > To: r-help@r-project.org > > Cc: > > Sent: Monday, June 17, 2013 2:29 PM > > Subject: [R] vector question > > > > Dear All, > > > > would you please help with the following: > > let us say I have: > > > > a <-c(0,1,12,13,24,25,36,37) > > b <-c(6,24.6,27) > > #then I extract every 2nd element from "a" > > d <-a[seq(1, length(a), 2)] > > > > and what I need help with is to extract the 1st value from d > > that is greater than the values in b, so as a result I > > should have "f" as: > > > > f <-c(12,36,36) > > > > appreciate the insights, > > > > thank you, > > > > Andras > > > > ______________________________________________ > > R-help@r-project.org > > mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible > > code. > > > > > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.