| Rle-utils {S4Vectors} | R Documentation |
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. The
digitsargument is used for number formatting withsignif().
Logical Data Methods
In the code snippets below, x is an Rle object:
!x:-
Returns logical negation (NOT) of
x. which(x):-
Returns an integer vector representing the
TRUEindices 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 of
x.lagAn integer indicating which lag to use.
differencesAn integer indicating the order of the difference.
pmax(..., na.rm = FALSE),pmax.int(..., na.rm = FALSE):-
Parallel maxima of the Rle input values. Removes
NAs whenna.rm = TRUE. pmin(..., na.rm = FALSE),pmin.int(..., na.rm = FALSE):-
Parallel minima of the Rle input values. Removes
NAs whenna.rm = TRUE. which.max(x):Returns the index of the first element matching the maximum value of
x.mean(x, na.rm = FALSE):-
Calculates the mean of
x. RemovesNAs whenna.rm = TRUE. var(x, y = NULL, na.rm = FALSE):-
Calculates the variance of
xor covariance ofxandyif both are supplied. RemovesNAs whenna.rm = TRUE. cov(x, y, use = "everything"),cor(x, y, use = "everything"):-
Calculates the covariance and correlation respectively of Rle objects
xandy. Theuseargument 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 of
x. RemovesNAs whenna.rm = TRUE. median(x, na.rm = FALSE):-
Calculates the median of
x. RemovesNAs whenna.rm = TRUE. quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, type = 7, ...):-
Calculates the specified quantiles of
x.probsA numeric vector of probabilities with values in [0,1].
na.rmIf
TRUE, removesNAs fromxbefore the quantiles are computed.namesIf
TRUE, the result has names describing the quantiles.typeAn 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 of
x.centerThe center to calculate the deviation from.
constantThe scale factor.
na.rmIf
TRUE, removesNAs fromxbefore the mad is computed.lowIf
TRUE, compute the 'lo-median'.highIf
TRUE, compute the 'hi-median'.
IQR(x, na.rm = FALSE):-
Calculates the interquartile range of
x.na.rmIf
TRUE, removesNAs fromxbefore the IQR is computed.
smoothEnds(y, k = 3):-
Smooth end points of an Rle
yusing subsequently smaller medians and Tukey's end point rule at the very end.kAn 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 of
x.typeOne of
c("bytes", "chars", "width").allowNAShould
NAbe 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 at
start/firstand ending atstop/last. chartr(old, new, x):-
Returns a character or factor Rle containing a translated version of
x.oldA character string specifying the characters to be translated.
newA character string specifying the translations.
tolower(x):-
Returns a character or factor Rle containing a lower case version of
x. toupper(x):-
Returns a character or factor Rle containing an upper case version of
x. 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. See
subfor 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. See
gsubfor 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.
droplevels(x):-
Drops unused factor levels.
Author(s)
P. Aboyoun
See Also
-
Rle objects.
Examples
x <- Rle(10:1, 1:10)
x
sqrt(x)
x^2 + 2 * x + 1
range(x)
sum(x)
mean(x)
z <- c("the", "quick", "red", "fox", "jumps", "over", "the", "lazy", "brown", "dog")
z <- Rle(z, seq_len(length(z)))
chartr("a", "@", z)
toupper(z)