[R] sequences extraction
jim holtman
jholtman at gmail.com
Fri Apr 20 13:23:19 CEST 2007
Here is one way of doing it:
> a
[1] 1 2 3 6 10 11 13
> b <- c(FALSE, diff(a) != 1)
> cumsum(b)
[1] 0 0 0 1 2 2 3
> split(a, cumsum(b))
$`0`
[1] 1 2 3
$`1`
[1] 6
$`2`
[1] 10 11
$`3`
[1] 13
>
On 4/20/07, Bruno C. <bruno.c at inwind.it> wrote:
> Hello,
>
> I need to extract sequences from an ordered vector.
> For example, if
> a<-c(1,2,3,6,10,11,13)
> I need to get the followings 4 vectors
> (1,2,3),(6),(10,11),(13)
>
> Thank You
> -Bruno
>
>
> ------------------------------------------------------
> Leggi GRATIS le tue mail con il telefonino i-mode™ di Wind
> http://i-mode.wind.it/
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list