[R] Counting indexes
Peter.Alspach at plantandfood.co.nz
Wed May 26 06:36:00 CEST 2010
Tena koe Robin
See rle - it doesn't do exactly what you want but by looking at the code
(simply enter rle without brackets) you should be able to get there.
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Robin Jeffries
> Sent: Wednesday, 26 May 2010 4:15 p.m.
> To: r-help at r-project.org
> Subject: [R] Counting indexes
> I have a vector of ID's like so,
> id <- c(1,2,2,3,3,3,4,5,5)
> I would like to create a [start,stop] pair of vectors that index the
> and last observation per ID.
> For the ID list above, it would look like
> 1 1
> 2 3
> 4 6
> 7 7
> 8 9
> I haven't worked with indexes/data manipulation much in R, so any
> would be helpful.
> Many thanks!
> -Robin Jeffries
> Dr.P.H. Candidate in Biostatistics
> UCLA School of Public Health
> rjeffries at ucla.edu
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help