Hi:

Try this:

with(rle(x), data.frame(Level = values, Count = lengths))
  Level Count
1     1     3
2     0     4
3     1     2
4     0     3
5     1     2
6     0     1

HTH,
Dennis

On Wed, Apr 14, 2010 at 7:11 PM, Pete B <peter.breckn...@bp.com> wrote:

>
> Hi All
>
> I have a vector x containing 2 levels
>
> x = c(1,1,1,0,0,0,0,1,1,0,0,0,1,1,0)
>
> I would like to derive the following summarization
>
> Level Count
> 1 3
> 0 4
> 1 2
> 0 3
> 1 2
> 0 1
>
> I have generated an inelegant solution using lags and loops but feel sure
> that there must be a better approach. If anyone has any thoughts I would be
> very grateful if you would share them.
>
> Thanks and best regards
>
> Pete
> --
> View this message in context:
> http://n4.nabble.com/Summarization-tp1840718p1840718.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to