rle {base} | R Documentation |
Compute the lengths and values of runs of equal values in a vector – or the reverse operation.
rle(x)
## S3 method for class 'rle'
print(x, digits = getOption("digits"), ...)
inverse.rle(x, ...)
x |
a simple vector for |
digits , ... |
potentially further arguments to the corresponding method. |
rle()
returns an object of class "rle"
which is a list
with components
lengths |
an integer vector containing the length of each run. |
values |
a vector of the same length as |
inverse.rle()
is the inverse function of rle()
.
x <- rev(rep(6:10, 1:5))
rle(x)
## lengths [1:5] 5 4 3 2 1
## values [1:5] 10 9 8 7 6
z <- c(TRUE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE)
rle(z)
rle(as.character(z))
stopifnot(x == inverse.rle(rle(x)),
z == inverse.rle(rle(z)))