rep.rle: A 'rep' method for 'rle' objects

Description Usage Arguments Note Examples

View source: R/rle_utils.R

Description

A rep method for rle objects

Usage

1
2
3
4
5
6
7
8
## S3 method for class '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.

Note

The rep method for rle objects is very limited at this time. Even though the default setting is to replicate elements of the vector, only the run-replicating functionality is implemented at this time except for the simplest case (scalar times argument).

Examples

1
2
3
4
5
6
7
8
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")))))

statnet/rle documentation built on Jan. 5, 2021, 3:31 a.m.