Rui and Dimitris, thank you much, both approaches work great! (although rle
won me, I had a feeling something like that had to exist)
--
View this message in context:
http://r.789695.n4.nabble.com/split-array-into-groups-by-value-tp4448578p4451048.html
Sent from the R help mailing list archive at
One approach is:
l <- c(1,1,1,1, 0,0,0,0,0, 1,1,1,1,1,1)
r <- rle(l)$lengths
split(l, rep(seq_along(r), r))
I hope it helps.
Best,
Dimitris
On 3/6/2012 3:53 AM, pavlo wrote:
I have an array
l<- c(1,1,1,1, 0,0,0,0,0, 1,1,1,1,1,1)
I would like to get a rugged array
[[1]] 1,1,1,1
[[2]] 0,0,0
Hello,
pavlo wrote
>
> I have an array
> l <- c(1,1,1,1, 0,0,0,0,0, 1,1,1,1,1,1)
>
> I would like to get a rugged array
> [[1]] 1,1,1,1
> [[2]] 0,0,0,0,0
> [[3]] 1,1,1,1,1,1
>
> catching every group of contiguous repeated values. Any help would be
> greatly appreciated!
> -Pavel
>
Is this
3 matches
Mail list logo