Learn R Programming

iterors (version 1.0)

i_rle: Run-length encoding iterator.

Description

This is an iterator equivalent of rle; it produces one output value for each run if identical values in its input, along with the lenght of the run. i_rle_inverse() performs the inverse transformstion.

Usage

i_rle(obj, cmp = identical, ...)

i_rleinv(obj, ...)

Value

An iterator returning entries of the form list(length=n, value=X).

i_rleinv recreates the original data from the output of i_rle.

Arguments

obj

An iterable

cmp

A function to use for comparison. It should take two arguments and return TRUE or FALSE.

...

further arguments forwarded to iteror(obj, ...).

Author

Peter Meilstrup

See Also

i_dedupe

Examples

Run this code
it <- isample(c(TRUE, FALSE), 1, replace=TRUE)
rle <- i_rle(it)
x <- take(rle, 10)
as.logical(i_rleinv(x))

Run the code above in your browser using DataLab