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?
Hi Edward,
You can get the default row medians by transposing the matrix and sending it to the "describe" function in the prettyR package:

describe(t(my.matrix),num.desc="median")

For choosing different methods of calculating the median, you can write a wrapper for the "quantile" function:

new.quantile<-function(x,na.rm=TRUE) return(quantile(x,probs=0.5,type=n,na.rm=na.rm))
describe(t(my.matrix),num.desc="my.median")

where "n" is the type of median calculation you want (see the help for quantile).

Jim

______________________________________________
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.

Reply via email to