[R] More efficient matrix computation

Wolski wolski at molgen.mpg.de
Tue Aug 31 18:37:03 CEST 2004


Hi!
apply(m,2,quantile,c(0.95,0.99))
/Eryk

*********** REPLY SEPARATOR  ***********

On 8/31/2004 at 9:16 AM JTW wrote:

>>>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
>>>follows:
>>>
>>>> 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
>>>
>>>______________________________________________
>>>R-help at stat.math.ethz.ch mailing list
>>>https://stat.ethz.ch/mailman/listinfo/r-help
>>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



Dipl. bio-chem. Witold Eryk Wolski             @         MPI-Moleculare Genetic   
Ihnestrasse 63-73 14195 Berlin                'v'    
tel: 0049-30-83875219                        /   \       
mail: witek96 at users.sourceforge.net        ---W-W----    http://www.molgen.mpg.de/~wolski 
      wolski at molgen.mpg.de




More information about the R-help mailing list