Sequence reduction in R

Posted by drknexus on Stack Overflow See other posts from Stack Overflow or by drknexus
Published on 2010-06-09T23:51:23Z Indexed on 2010/06/10 0:12 UTC
Read the original article Hit count: 532

Filed under:
|
|
|
|

Assume you have a vector like so:

v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3)

How can it be best reduced to a data.frame like this?

v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4))

In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is inefficient. Any advice?

© Stack Overflow or respective owner

Related posts about r

    Related posts about sequence