This help topic is for R version 1.1. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/base/html/rle.html
rle {base}R Documentation

Run Length Encoding

Description

Compute the lengths and values of runs of equal values in a vector.

Usage

rle(x)

Arguments

x

a (numerical, logical or character) vector.

Value

A list with components

lengths

a vector containing the length of each run.

values

a vector of the same length as lengths with the corresponding values.

Examples

x <- rev(rep(6:10, 1:5))
rle(x)
## $lengths
## [1] 5 4 3 2 1
## $values
## [1] 10  9  8  7  6
z <- c(T,T,F,F,T,F,T,T,T)
rle(z)
rle(as.character(z))

[Package base version 1.1 ]