[R] counts of a vector
Wu Gong
ghowoo at gmail.com
Wed May 26 23:09:27 CEST 2010
### Special cumsum
### Do cumsum when TRUE, and reset to 0 when FALSE
x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE )
## The rle function computes the lengths of equal values of a vector
## And gives two vecters: $lengths and $values
## The sequence function creates and concatenates sequences by a integers
vector
x*sequence(rle(x)$lengths)
-----
A R learner.
--
View this message in context: http://r.789695.n4.nabble.com/counts-of-a-vector-tp2232047p2232338.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list