Edward, In general, if you have an nxn matrix, you can use the "apply" function to apply a function to each row of the matrix, and return the result.
So, as a start, you could do, apply(your.mat, 1, median) or apply(your.mat, 1, median, na.rm = TRUE) if you want to pass further arguments to median... You can also write your own function and pass it in, of course: E.g., apply(your.mat, 1, function(x) sum(x)+1001) See ?apply. -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Edward Chen Sent: Friday, August 21, 2009 11:50 AM To: r-help@r-project.org Subject: [R] help with median for each row 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! -- Edward Chen [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.