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:13))
and, from 'b' I wish to create vector 'c':
c=c(
NA,NA,NA,NA,NA
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),sort(6:11,decreasing=TRUE),
(7:13))
and, from 'b' I wish to create vector
To: 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][[i]]-
rep(i,length(lst1[indx
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)
.
- Original Message -
From: arun smartpink...@yahoo.com
To: Benjamin Gillespie gy...@leeds.ac.uk
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
5 matches
Mail list logo