[R] help with median for each row

Greg Hirson ghirson at ucdavis.edu
Fri Aug 21 18:55:53 CEST 2009


See ?apply

x = matrix(rnorm(100), ncol = 10)
apply(x, 1, median)

Hope this helps,


Edward Chen wrote:
> Hi,
> I tried looking through google search on whether there's a way to computer
> the median for each row of a nxn matrix and return the medians for each row
> for further computation.
> And also if the number of columns in the matrix are even, how could I
> specify which median to use?
> Thank you very much!

Greg Hirson
ghirson at ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

More information about the R-help mailing list