Skip to contents

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, ...)

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, ...).

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.

See also

i_dedupe

Author

Peter Meilstrup

Examples

it <- isample(c(TRUE, FALSE), 1, replace=TRUE)
rle <- i_rle(it)
x <- take(rle, 10)
as.logical(i_rleinv(x))
#>  [1]  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE
#> [13]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE