Learn R Programming

matrixStats (version 0.60.0)

rowIQRs: Estimates of the interquartile range for each row (column) in a matrix

Description

Estimates of the interquartile range for each row (column) in a matrix.

Usage

rowIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = NA)

colIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = NA)

iqr(x, idxs = NULL, na.rm = FALSE, ...)

Arguments

x

An NxK matrix or, if dim. is specified, an N * K vector.

rows

A vector indicating subset of rows to operate over. If NULL, no subsetting is done.

cols

A vector indicating subset of columns to operate over. If NULL, no subsetting is done.

na.rm

If TRUE, missing values are excluded.

...

Additional arguments passed to rowQuantiles() (colQuantiles()).

useNames

If NA, the default behavior of the function about naming support is remained. If FALSE, no naming support is done. Else if TRUE, names attributes of result are set.

idxs

A vector indicating subset of elements to operate over. If NULL, no subsetting is done.

Value

Returns a numeric vector of length N (K).

Missing values

Contrary to IQR, which gives an error if there are missing values and na.rm = FALSE, iqr() and its corresponding row and column-specific functions return NA_real_.

See Also

See IQR. See rowSds().

Examples

Run this code
# NOT RUN {
set.seed(1)

x <- matrix(rnorm(50 * 40), nrow = 50, ncol = 40)
str(x)

# Row IQRs
q <- rowIQRs(x)
print(q)
q0 <- apply(x, MARGIN = 1, FUN = IQR)
stopifnot(all.equal(q0, q))

# Column IQRs
q <- colIQRs(x)
print(q)
q0 <- apply(x, MARGIN = 2, FUN = IQR)
stopifnot(all.equal(q0, q))
# }

Run the code above in your browser using DataLab