rle2: Run Length Encoding with Indices

Description Usage Arguments Details Value Examples

Description

Compute the lengths, values and indices of runs of equal values in a vector. This is a modifed version of base function rle().

Usage

1
2
3
4
rle2(x)

## S3 method for class 'rle2'
print(x, digits = getOption("digits"), prefix = "", ...)

Arguments

x

an atomic vector for rle(); an object of class "rle" for inverse.rle().

...

further arguments; ignored here.

digits

number of significant digits for printing, see print.default.

prefix

character string, prepended to each printed line.

Details

Missing values are regarded as unequal to the previous value, even if that is also missing.

inverse.rle() is the inverse function of rle2() and rle(), reconstructing x from the runs.

Value

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 lengths with the corresponding values.

Examples

1
2
3
4
5
6
7
8
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
rle2(x)
## lengths: int [1:5] 5 4 3 2 1
## values : int [1:5] 10 9 8 7 6
## indices: int [1:5] 5 9 12 14 15


Search within the bio3d package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.