[R] How should i get the quantile 2.5 % and 97.5% in each row of a matrix?
Chuck Cleland
ccleland at optonline.net
Fri Jun 1 10:41:25 CEST 2007
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
More information about the R-help
mailing list