Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Rle-utils

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 digits argument is used for number formatting with signif().

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 TRUE indices of x.

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.

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. Removes NAs when na.rm = TRUE.

pmin(..., na.rm = FALSE), pmin.int(..., na.rm = FALSE): Parallel minima of the Rle input values. Removes NAs when na.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. Removes NAs when na.rm = TRUE.

var(x, y = NULL, na.rm = FALSE): Calculates the variance of x or covariance of x and y if both are supplied. Removes NAs when na.rm = TRUE.

cov(x, y, use = "everything"), cor(x, y, use = "everything"): Calculates the covariance and correlation respectively of Rle objects x and y. The use 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 of x. Removes NAs when na.rm = TRUE.

median(x, na.rm = FALSE): Calculates the median of x. Removes NAs when na.rm = TRUE.

quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, type = 7, ...): Calculates the specified quantiles of x.

probs

A numeric vector of probabilities with values in [0,1].

na.rm

If TRUE, removes NAs from x 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 of x.

center

The center to calculate the deviation from.

constant

The scale factor.

na.rm

If TRUE, removes NAs from x before the mad is computed.

low

If TRUE, compute the 'lo-median'.

high

If TRUE, compute the 'hi-median'.

IQR(x, na.rm = FALSE): Calculates the interquartile range of x.

na.rm

If TRUE, removes NAs from x before the IQR is computed.

smoothEnds(y, k = 3): Smooth end points of an Rle y 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 of x.

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 at start/first and ending at stop/last.

chartr(old, new, x): Returns a character or factor Rle containing a translated version of x.

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 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 sub 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. See gsub 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.

droplevels(x): Drops unused factor levels.

Author(s)

P. Aboyoun

See Also

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)

S4Vectors

Foundation of vector-like and list-like containers in Bioconductor

v0.28.1
Artistic-2.0
Authors
H. Pagès, M. Lawrence and P. Aboyoun
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.