rowMedians {Biobase} | R Documentation

## Calculates the median for each row in a matrix

### Description

Calculates the median for each row in a matrix.

### Usage

    rowMedians(imat, na.rm=FALSE)

### Arguments

`imat` | A `numeric` `matrix`.
`na.rm` | If `TRUE`, `NA`s are excluded before calculating the medians, otherwise not.
`...` | Not use.

### Value

Returns a `double` `vector` of length equal to number of rows in `x`.

### Missing values

Missing values are excluded before calculating the medians.

### Benchmarking

This implementation is optimized for speed and memory to calculate. As the example shows, this implementation is roughly 3-10 times faster than using `apply(x, MARGIN=1, FUN=medians)`. As the example might show, the `rowQ()` does not (have to) handle missing values, and is therefore in some cases faster.

### Author(s)

Henrik Bengtsson

### See Also

See `rowMeans()` in `colSums`().

### Examples

    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)))

[Package Biobase version 2.2.2 Index]