[R] vector question

arun smartpink111 at yahoo.com
Mon Jun 17 20:45:10 CEST 2013


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.



More information about the R-help mailing list