index_to_run {rle} | R Documentation |
Map an element in a vector represented by an rle
to its run
Description
Map an element in a vector represented by an rle
to its run
Usage
index_to_run(x, i, ...)
## S3 method for class 'rle'
index_to_run(x, i, ...)
Arguments
x |
an |
i |
a numeric vector of indices to map; fractional values are rounded down. |
... |
additional arguments to methods. |
Value
An integer vector. Negative values of i
and 0 are always
mapped to 0. Indexes above the range represented by x
are
mapped to the number of runs + 1.
Note
This function is generic for future-proofing.
Examples
# From example(rle):
z <- c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE)
rle(z)
stopifnot(identical(
index_to_run(rle(z), (-1):10),
c(0L, 0L, 1L, 1L, 2L, 2L, 3L, 4L, 5L, 5L, 5L, 6L)
))
[Package rle version 0.10.0 Index]