index_to_run | R Documentation |
rle
to its runMap an element in a vector represented by an rle
to its run
index_to_run(x, i, ...)
## S3 method for class 'rle'
index_to_run(x, i, ...)
x |
an |
i |
a numeric vector of indices to map; fractional values are rounded down. |
... |
additional arguments to methods. |
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.
This function is generic for future-proofing.
# 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)
))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.