Re: [R] Possible loop/ if statement query

2013-10-11 Thread Benjamin Gillespie
alf Of Benjamin Gillespie > Sent: Thursday, October 10, 2013 12:39 AM > To: r-help@R-project.org > Subject: [R] Possible loop/ if statement query > > Dear r genii, > > I hope you can help. > > I have vector 'b': > > b=c((1:10),sort(1:9,decreasing=TRUE),(2:12)

Re: [R] Possible loop/ if statement query

2013-10-11 Thread PIKAL Petr
, October 10, 2013 12:39 AM > To: r-help@R-project.org > Subject: [R] Possible loop/ if statement query > > Dear r genii, > > I hope you can help. > > I have vector 'b': > > b=c((1:10),sort(1:9,decreasing=TRUE),(2:12),sort(6:11,decreasing=TRUE), > (7:

Re: [R] Possible loop/ if statement query

2013-10-10 Thread Benjamin Gillespie
: Benjamin Gillespie Cc: R help Subject: Re: [R] Possible loop/ if statement query Hi, Try: b1<- b b1[!b1>=7]<- NA lst1 <- split(b1,cumsum(c(0,abs(diff(b>=7) indx <- as.logical(((seq_along(lst1)-1)%%2)) lst1[indx]<- lapply(seq_along(lst1[indx]),function(i) {lst1[indx]

Re: [R] Possible loop/ if statement query

2013-10-09 Thread arun
LSE)  all.equal(c1,C2) #[1] TRUE A.K. - Original Message - From: arun To: Benjamin Gillespie Cc: Sent: Wednesday, October 9, 2013 8:19 PM Subject: Re: [R] Possible loop/ if statement query Hi, There should be a simpler way with cumsum(diff()). b=c((1:10),sort(1:9,decreasing=TRUE),

[R] Possible loop/ if statement query

2013-10-09 Thread Benjamin Gillespie
Dear r genii, I hope you can help. I have vector 'b': b=c((1:10),sort(1:9,decreasing=TRUE),(2:12),sort(6:11,decreasing=TRUE),(7:13)) and, from 'b' I wish to create vector 'c': c=c( NA,NA,NA,NA,NA,NA,1,1,1,1,1,1,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,2,2,2,2,2,2,2,2,2,2,2,NA,3,3,3,3,3,3,3) The