Summary.rle {rle} | R Documentation |
Summary methods for rle
objects.
Description
Summarisation functions for vectors described in Summary are implemented for rle
objects.
Usage
## S3 method for class 'rle'
Summary(..., na.rm)
Arguments
... |
|
na.rm |
Whether the missing values should be ignored ( |
Details
Supported functions include all elements of the S3
Summary group. As of this writing, functions supported include
(from R help) all
, any
, max
, min
, prod
, range
, and
sum
.
Value
In every supported case, the call should produce the same
result as what would have resulted had the call been applied to
the original (uncompressed) vector. (At no point in the
calculation is the uncompressed vector actually constructed, of
course.) The exception is that if values
are of class
integer
, the result will nonetheless always be upcast to
numeric
to avert overflows. This behaviour may change in the
future.
Examples
x <- rle(as.logical(rbinom(20,1,.7)))
y <- rle(as.logical(rbinom(20,1,.3)))
stopifnot(isTRUE(all.equal(any(x, y),any(inverse.rle(x), inverse.rle(y)))))
stopifnot(isTRUE(all.equal(any(y),any(inverse.rle(y)))))
stopifnot(isTRUE(all.equal(sum(inverse.rle(x),inverse.rle(y)),sum(x,y))))
stopifnot(isTRUE(all.equal(sum(inverse.rle(y)),sum(y))))
y$values[2:3] <- NA
stopifnot(isTRUE(all.equal(sum(inverse.rle(y), na.rm=TRUE),sum(y, na.rm=TRUE))))
stopifnot(isTRUE(all.equal(sum(inverse.rle(y), na.rm=FALSE),sum(y, na.rm=FALSE))))