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 <motyocska at yahoo.com>
To: arun <smartpink111 at 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 <smartpink111 at yahoo.com> wrote:
> From: arun <smartpink111 at yahoo.com>
> Subject: Re: [R] vector question
> To: "Andras Farkas" <motyocska at yahoo.com>
> Cc: "R help" <r-help at 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 <motyocska at yahoo.com>
> To: r-help at 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 at 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.
>
>