[R] Concecutive zeros and ones
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Thu Oct 6 09:22:16 CEST 2011
Check function rle().
I hope it helps.
Best,
Dimitris
On 10/6/2011 9:18 AM, Alaios wrote:
> Dear all,
> I have a data series (might be vector or matrix) which is composed only from zeros and ones like the following example
>
> 0 0 0 1 1 0 1 0 0 1 1 1 1 0 0 0
>
> I want to be able to return back the length of concecutive zeros and the length of concecutive ones.
>
> For that I want to have something like that returned:
>
>
> zeros= [3 1 2 3];
> ones=[2 1 4];
>
> How I can do that simply in R?
>
> I would like to thank you in advance for your help
>
>
> B.R
> Alex
>
> [[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________
> 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.
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
More information about the R-help
mailing list