na.rm: if TRUE, NAs are excluded first, otherwise not.
hasNA: logical indicating if x may contain NAs. If set to FALSE, no internal NA handling is performed which typically is faster.
keep.names: logical indicating if row or column names of x
should become names of the result - as is the case for apply(x, MM, median).
Returns
a numeric vector of length n or p, respectively.
Missing values
Missing values are excluded before calculating the medians unlesshasNA is false. Note that na.rm has no effect and is automatically false when hasNA is false, i.e., internally, before computations start, the following is executed:
if (!hasNA) ## If there are no NAs, don't try to remove them
narm <- FALSE
Details
The implementation of rowMedians() and colMedians()
is optimized for both speed and memory. To avoid coercing to doubles (and hence memory allocation), there is a special implementation for integer matrices. That is, if x is an integermatrix, then rowMedians(as.double(x)) (rowMedians(as.double(x))) would require three times the memory of rowMedians(x)
(colMedians(x)), but all this is avoided.
Author(s)
Henrik Bengtsson, Harris Jaffee, Martin Maechler
See Also
See wgt.himedian() for a weighted hi-median, and colWeightedMedians() etc from package list("matrixStats") for weighted medians.