Learn R Programming

matrixStats (version 0.8.5)

rowQuantiles: Estimates quantiles for each row (column) in a matrix

Description

Estimates quantiles for each row (column) in a matrix.

Usage

rowQuantiles(x, probs=seq(from=0, to=1, by=0.25), ..., drop=TRUE)
 colQuantiles(x, ...)

Arguments

x
A numeric NxK matrix with N >= 0.
probs
A numeric vector of J probabilities in [0,1].
...
Additional arguments passed to quantile.
drop
If TRUE, singleton dimensions in the result are dropped, otherwise not.

Value

  • Returns a numeric JxN (JxK) matrix, where N (K) is the number of rows (columns) for which the J quantiles are calculated.

See Also

quantile.

Examples

Run this code
set.seed(1)

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

probs <- c(0.25,0.5,0.75)

# Row quantiles
q <- rowQuantiles(x, probs=probs)
print(q)
q0 <- apply(x, MARGIN=1, FUN=quantile, probs=probs)
stopifnot(all.equal(q0, t(q)))

# Column IQRs
q <- colQuantiles(x, probs=probs)
print(q)
q0 <- apply(x, MARGIN=2, FUN=quantile, probs=probs)
stopifnot(all.equal(q0, t(q)))

Run the code above in your browser using DataLab