# rowMedians: Calculates the median for each row in a matrix In Biobase: Biobase: Base functions for Bioconductor

## Description

Calculates the median for each row in a matrix.

## Usage

 `1` ```rowMedians(x, na.rm=FALSE, ...) ```

## Arguments

 `x` A `numeric` NxK `matrix`. `na.rm` If `TRUE`, `NA`s are excluded first, otherwise not. `...` Not use.

## Details

The implementation of `rowMedians()` is optimized for both speed and memory. To avoid coercing to `double`s (and hence memory allocation), there is a special implementation for `integer` matrices. That is, if `x` is an `integer` `matrix`, then `rowMedians(as.double(x))` would require three times the memory of `rowMedians(x)`, but all this is avoided.

## Value

Returns a `numeric` `vector` of length N.

## Missing values

Missing values are excluded before calculating the medians.

## Author(s)

Henrik Bengtsson

See `rowMeans()` in `colSums`().
 ``` 1 2 3 4 5 6 7 8 9 10``` ```set.seed(1) x <- rnorm(n=234*543) x[sample(1:length(x), size=0.1*length(x))] <- NA dim(x) <- c(234,543) y1 <- rowMedians(x, na.rm=TRUE) y2 <- apply(x, MARGIN=1, FUN=median, na.rm=TRUE) stopifnot(all.equal(y1, y2)) x <- cbind(x1=3, x2=c(4:1, 2:5)) stopifnot(all.equal(rowMeans(x), rowMedians(x))) ```