# rowMedians: Calculates the median for each row (column) in a matrix In matrixStats: Functions that Apply to Rows and Columns of Matrices (and to Vectors)

## Description

Calculates the median for each row (column) in a matrix.

## Usage

 ```1 2 3 4 5``` ```rowMedians(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), ..., useNames = NA) colMedians(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), ..., useNames = NA) ```

## Arguments

 `x` An NxK `matrix` or, if `dim.` is specified, an N * K `vector`. `rows, cols` A `vector` indicating subset of rows (and/or columns) to operate over. If `NULL`, no subsetting is done. `na.rm` If `TRUE`, `NA`s are excluded first, otherwise not. `dim.` An `integer` `vector` of length two specifying the dimension of `x`, also when not a `matrix`. `...` Not used. `useNames` If `NA`, the default behavior of the function about naming support is remained. If `FALSE`, no naming support is done. Else if `TRUE`, names attributes of result are set.

## Details

The implementation of `rowMedians()` and `colMedians()` 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))` (`rowMedians(as.double(x))`) would require three times the memory of `rowMedians(x)` (`colMedians(x)`), but all this is avoided.

## Value

Returns a `numeric` `vector` of length N (K).

## Author(s)

Henrik Bengtsson, Harris Jaffee

See `rowWeightedMedians()` and `colWeightedMedians()` for weighted medians. For mean estimates, see `rowMeans2()` and `rowMeans()`.