Learn R Programming

rle (version 0.9.2)

rep.rle: A rep method for rle objects

Description

A rep method for rle objects

Usage

# S3 method for rle
rep(
  x,
  ...,
  scale = c("element", "run"),
  doNotCompact = FALSE,
  doNotCompress = doNotCompact
)

Arguments

x

an rle object.

...

see documentation for rep.

scale

whether to replicate the elements of the RLE-compressed vector or the runs.

doNotCompress, doNotCompact

whether the method should call compress.rle the results before returning. Methods liable to produce very long output vectors, like rep, have this set FALSE by default. doNotCompact is an old name for this argument.

Examples

Run this code
# NOT RUN {
x <- rle(sample(c(-1,+1), 10, c(.7,.3), replace=TRUE))
y <- rpois(length(x$lengths), 2)

stopifnot(isTRUE(all.equal(rep(inverse.rle(x), rep(y, x$lengths)),
                               inverse.rle(rep(x, y, scale="run")))))

stopifnot(isTRUE(all.equal(rep(inverse.rle(x), max(y)),
                               inverse.rle(rep(x, max(y), scale="element")))))

# }

Run the code above in your browser using DataLab