### 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. ______________________________________________ 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.