compress.rle {rle} | R Documentation |
Compress the rle
object by merging adjacent runs
Description
Compress the rle
object by merging adjacent runs
Usage
## S3 method for class 'rle'
compress(x, ...)
Arguments
x |
an |
... |
additional objects; if given, all arguments are concatenated. |
Note
Since rle
stores run lengths as integers, compress.rle
will not merge runs that add up to lengths greater than what can
be represented by a 32-bit signed integer
(2147483647).
Examples
x <- rle(as.logical(rbinom(10,1,.7)))
y <- rle(as.logical(rbinom(10,1,.3)))
stopifnot(identical(rle(inverse.rle(x)&inverse.rle(y)),compress(x&y)))
big <- structure(list(lengths=as.integer(rep(.Machine$integer.max/4,6)),
values=rep(TRUE,6)), class="rle")
stopifnot(all(aggregate(as.numeric(lengths)~values,
data=as.data.frame(unclass(big)),FUN=sum)
==
aggregate(as.numeric(lengths)~values,
data=as.data.frame(unclass(compress(big))),
FUN=sum)))
[Package rle version 0.9.2 Index]