zhijie zhang
2007-Jun-01 08:31 UTC
[R] How should i get the quantile 2.5 % and 97.5% in each row of a matrix?
Dear friends, I need the get the 2.5% and 97.5% quantile from each row of a matrix, how should i get it? BTW, i can get the min/max value from each row of a matrix, using the following programs, is there an easy function to do it? simmin<-matrix(NA,nrow=47,ncol=1) for (i in 1:47) { simmin[i,]<-min(datas[i,]) } Thanks for your help. -- With Kind Regards, oooO::::::::: (..)::::::::: :\.(:::Oooo:: ::\_)::(..):: :::::::)./::: ::::::(_/:::: ::::::::::::: [***********************************************************************] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:epistat@gmail.com Website: www.statABC.com [***********************************************************************] oooO::::::::: (..)::::::::: :\.(:::Oooo:: ::\_)::(..):: :::::::)./::: ::::::(_/:::: ::::::::::::: [[alternative HTML version deleted]]
Chuck Cleland
2007-Jun-01 08:41 UTC
[R] How should i get the quantile 2.5 % and 97.5% in each row of a matrix?
zhijie zhang wrote:> Dear friends, > I need the get the 2.5% and 97.5% quantile from each row of a matrix, how > should i get it? > BTW, i can get the min/max value from each row of a matrix, using the > following programs, is there an easy function to do it? > > simmin<-matrix(NA,nrow=47,ncol=1) > for (i in 1:47) { > simmin[i,]<-min(datas[i,]) > } > > Thanks for your help.mymat <- matrix(rnorm(200), ncol=50) apply(mymat, 1, quantile, probs = c(0.025,0.975)) [,1] [,2] [,3] [,4] 2.5% -1.690786 -1.691700 -1.678078 -1.564438 97.5% 1.970500 1.954904 2.249030 1.862571 apply(mymat, 1, max) [1] 2.179982 2.257138 2.772428 2.579247 apply(mymat, 1, min) [1] -2.830661 -1.989114 -1.710050 -2.316970 ?apply -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894