1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rowQuantiles.R
\name{rowQuantiles}
\alias{rowQuantiles}
\alias{colQuantiles}
\title{Estimates quantiles for each row (column) in a matrix}
\usage{
rowQuantiles(x, rows = NULL, cols = NULL, probs = seq(from = 0, to = 1,
by = 0.25), na.rm = FALSE, type = 7L, digits = 7L, ...,
useNames = TRUE, drop = TRUE)
colQuantiles(x, rows = NULL, cols = NULL, probs = seq(from = 0, to = 1,
by = 0.25), na.rm = FALSE, type = 7L, digits = 7L, ...,
useNames = TRUE, drop = TRUE)
}
\arguments{
\item{x}{An \code{\link[base]{integer}}, \code{\link[base]{numeric}} or
\code{\link[base]{logical}} NxK \code{\link[base]{matrix}} with N >= 0.}
\item{rows}{A \code{\link[base]{vector}} indicating subset of rows to
operate over. If \code{\link[base]{NULL}}, no subsetting is done.}
\item{cols}{A \code{\link[base]{vector}} indicating subset of columns to
operate over. If \code{\link[base]{NULL}}, no subsetting is done.}
\item{probs}{A \code{\link[base]{numeric}} \code{\link[base]{vector}} of J
probabilities in [0, 1].}
\item{na.rm}{If \code{\link[base:logical]{TRUE}}, missing values are
excluded.}
\item{type}{An \code{\link[base]{integer}} specifying the type of estimator.
See \code{\link[stats]{quantile}} for more details.}
\item{digits}{An \code{\link[base]{integer}} specifying the precision of
the formatted percentages. Not used when `useNames = FALSE`.
In **matrixStats** (< 0.63.0), the default used to be
`max(2L, getOption("digits"))` in line with R (< 4.1.0).}
\item{...}{Additional arguments passed to \code{\link[stats]{quantile}}.}
\item{useNames}{If \code{\link[base:logical]{TRUE}} (default), names
attributes of the result are set, otherwise not.}
\item{drop}{If TRUE, singleton dimensions in the result are dropped,
otherwise not.}
}
\value{
Returns a NxJ (KxJ) \code{\link[base]{matrix}}, where N (K) is the
number of rows (columns) for which the J quantiles are calculated.
The return type is either integer or numeric depending on \code{type}.
}
\description{
Estimates quantiles for each row (column) in a matrix.
}
\examples{
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)
q_0 <- apply(x, MARGIN = 1, FUN = quantile, probs = probs)
stopifnot(all.equal(q_0, t(q)))
# Column IQRs
q <- colQuantiles(x, probs = probs)
print(q)
q_0 <- apply(x, MARGIN = 2, FUN = quantile, probs = probs)
stopifnot(all.equal(q_0, t(q)))
}
\seealso{
\code{\link[stats]{quantile}}.
}
\author{
Henrik Bengtsson
}
\keyword{array}
\keyword{iteration}
\keyword{robust}
\keyword{univar}
|