[R] function for rowMedian?

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Jan 20 16:39:21 CET 2006



Max Kauer wrote:
> Hi
> is anybody aware of a function to calculate a the median for specified
> columns in a dataframe or matrix - so analogous to rowMeans?
> Thanks
> Max
> 
> --
> 

No equivalent in base R, but you could always use ?apply:

apply(x, 1, median)

assuming "x" is an array or is coercible to a array.

I have a C-function that does this as part of my personal R package (not 
available from CRAN). It has the same time savings as "rowMeans" has 
over apply(x, 1, mean). Contact me offline if you would like a copy.

HTH,

--sundar




More information about the R-help mailing list