[R] summarize logical string

dbajic at cnb.csic.es dbajic at cnb.csic.es
Tue Mar 31 11:20:39 CEST 2009


Thank you very much, rapid and very helpful.

Best,
Djordje


> you need rle(), e.g.,
>
> x <- c(0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0)
> rle(x)$lengths
>
>
> I hope it helps.
>
> Best,
> Dimitris
>
>
> dbajic at cnb.csic.es wrote:
>> Hello everyone,
>>
>> I am a newbie, working on a gene clustering problem, and I have problems
>> in summarizing a logical string into number of repeats of each value. In
>> other words, how could I obtain from
>>
>> 0 1 1 1 0 0 0 0 1 1 0 1 0 0
>>
>> this: 1 3 4 2 1 1 2
>>
>> so a string that gives me the number of repeated values, no matter zeros
>> or ones.
>>
>> I've been diving in the manuals and the mailing list but, nothing
>> interesting, apparently... I would be very grateful if anyone could give
>> me some advice.
>>
>> Djordje Bajic
>> Logic of Genomic Systems Lab
>> Centro Nacional De Biotecnología - CSIC
>> Cantoblanco, Madrid, España
>>
>> ______________________________________________
>> 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
>




More information about the R-help mailing list