compress.rle | R Documentation |
rle
object by merging adjacent runsCompress the rle
object by merging adjacent runs
## S3 method for class 'rle'
compress(x, ...)
x |
an |
... |
additional objects; if given, all arguments are concatenated. |
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
(\Sexpr{.Machine$integer.max}).
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.