Common operations on Rle objects
Description
Common operations on Rle objects.
Group Generics
Rle objects have support for S4 group generic functionality:
Arith
"+"
,""
,"*"
,"^"
,"%%"
,"%/%"
,"/"
Compare
"=="
,">"
,"<"
,"!="
,"<="
,">="
Logic
"&"
,""
Ops
"Arith"
,"Compare"
,"Logic"
Math
"abs"
,"sign"
,"sqrt"
,"ceiling"
,"floor"
,"trunc"
,"cummax"
,"cummin"
,"cumprod"
,"cumsum"
,"log"
,"log10"
,"log2"
,"log1p"
,"acos"
,"acosh"
,"asin"
,"asinh"
,"atan"
,"atanh"
,"exp"
,"expm1"
,"cos"
,"cosh"
,"sin"
,"sinh"
,"tan"
,"tanh"
,"gamma"
,"lgamma"
,"digamma"
,"trigamma"
Math2
"round"
,"signif"
Summary
"max"
,"min"
,"range"
,"prod"
,"sum"
,"any"
,"all"
Complex
"Arg"
,"Conj"
,"Im"
,"Mod"
,"Re"
See S4groupGeneric for more details.
Summary
In the code snippets below, x
is an Rle object:

summary(object, ..., digits = max(3, getOption("digits")  3))
: Summarizes the Rle object using an atomic vector convention. Thedigits
argument is used for number formatting withsignif()
.
Logical Data Methods
In the code snippets below, x
is an Rle object:

!x
: Returns logical negation (NOT) ofx
. 
which(x)
: Returns an integer vector representing theTRUE
indices ofx
.
Numerical Data Methods
In the code snippets below, x
is an Rle object:

diff(x, lag = 1, differences = 1
: Returns suitably lagged and iterated differences ofx
.lag
An integer indicating which lag to use.
differences
An integer indicating the order of the difference.

pmax(..., na.rm = FALSE)
,pmax.int(..., na.rm = FALSE)
: Parallel maxima of the Rle input values. RemovesNA
s whenna.rm = TRUE
. 
pmin(..., na.rm = FALSE)
,pmin.int(..., na.rm = FALSE)
: Parallel minima of the Rle input values. RemovesNA
s whenna.rm = TRUE
. 
which.max(x)
: Returns the index of the first element matching the maximum value ofx
. 
mean(x, na.rm = FALSE)
: Calculates the mean ofx
. RemovesNA
s whenna.rm = TRUE
. 
var(x, y = NULL, na.rm = FALSE)
: Calculates the variance ofx
or covariance ofx
andy
if both are supplied. RemovesNA
s whenna.rm = TRUE
. 
cov(x, y, use = "everything")
,cor(x, y, use = "everything")
: Calculates the covariance and correlation respectively of Rle objectsx
andy
. Theuse
argument is an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings"everything"
,"all.obs"
,"complete.obs"
,"na.or.complete"
, or"pairwise.complete.obs"
. 
sd(x, na.rm = FALSE)
: Calculates the standard deviation ofx
. RemovesNA
s whenna.rm = TRUE
. 
median(x, na.rm = FALSE)
: Calculates the median ofx
. RemovesNA
s whenna.rm = TRUE
. 
quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, type = 7, ...)
: Calculates the specified quantiles ofx
.probs
A numeric vector of probabilities with values in [0,1].
na.rm
If
TRUE
, removesNA
s fromx
before the quantiles are computed.names
If
TRUE
, the result has names describing the quantiles.type
An integer between 1 and 9 selecting one of the nine quantile algorithms detailed in
quantile
. ...
Further arguments passed to or from other methods.

mad(x, center = median(x), constant = 1.4826, na.rm = FALSE, low = FALSE, high = FALSE)
: Calculates the median absolute deviation ofx
.center
The center to calculate the deviation from.
constant
The scale factor.
na.rm
If
TRUE
, removesNA
s fromx
before the mad is computed.low
If
TRUE
, compute the 'lomedian'.high
If
TRUE
, compute the 'himedian'.

IQR(x, na.rm = FALSE)
: Calculates the interquartile range ofx
.na.rm
If
TRUE
, removesNA
s fromx
before the IQR is computed.

smoothEnds(y, k = 3)
: Smooth end points of an Rley
using subsequently smaller medians and Tukey's end point rule at the very end.k
An integer indicating the width of largest median window; must be odd.
Character Data Methods
In the code snippets below, x
is an Rle object:

nchar(x, type = "chars", allowNA = FALSE)
: Returns an integer Rle representing the number of characters in the corresponding values ofx
.type
One of
c("bytes", "chars", "width")
.allowNA
Should
NA
be returned for invalid multibyte strings rather than throwing an error?

substr(x, start, stop)
,substring(text, first, last = 1000000L)
: Returns a character or factor Rle containing the specified substrings beginning atstart
/first
and ending atstop
/last
. 
chartr(old, new, x)
: Returns a character or factor Rle containing a translated version ofx
.old
A character string specifying the characters to be translated.
new
A character string specifying the translations.

tolower(x)
: Returns a character or factor Rle containing a lower case version ofx
. 
toupper(x)
: Returns a character or factor Rle containing an upper case version ofx
. 
sub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE)
: Returns a character or factor Rle containing replacements based on matches determined by regular expression matching. Seesub
for a description of the arguments. 
gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE)
: Returns a character or factor Rle containing replacements based on matches determined by regular expression matching. Seegsub
for a description of the arguments. 
paste(..., sep = " ", collapse = NULL)
: Returns a character or factor Rle containing a concatenation of the values in...
.
Factor Data Methods
In the code snippets below, x
is an Rle object:

levels(x)
,levels(x) < value
: Gets and sets the factor levels, respectively. 
nlevels(x)
: Returns the number of factor levels.
Author(s)
P. Aboyoun
See Also
Rle objects
S4groupGeneric
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 