[R] More efficient matrix computation

JTW jack_wang2000 at yahoo.com
Tue Aug 31 18:16:50 CEST 2004

I have a 20x3 matrix as follows:

> m <- replicate(3, matrix(rnorm(20),20,1))

I need to compute, say, 95th and 99th percentiles of
each column such that the resulting matrix becomes 2x3
with each row representing the respective percentile. 
My "best effort" is to compute one column at a time as

> quantile(m[,1], c(0.95, 0.99))

To do the same for columns 2 and 3, I would simply
change the column number accordingly.  Clearly, this
is not very efficient as I may have a large matrix
(e.g., 100,000x500) to work with.  Any help with the
code is appreciated.

Jack Wang

More information about the R-help mailing list