[R] Matrix oriented computing

From: Sigbert Klinke <sigbert_at_wiwi.hu-berlin.de>
Date: Fri 26 Aug 2005 - 22:44:10 EST


Hi,

I want to compute the quantiles of Chi^2 distributions with different degrees of freedom like

x<-cbind(0.005, 0.010, 0.025, 0.05, 0.1, 0.5, 0.9, 0.95, 0.975, 0.99, 0.995) df<-rbind(1:100)
m<-qchisq(x,df)

and hoped to get back a length(df) times length(x) matrix with the quantiles. Since this does not work, I use

x<-c(0.005, 0.010, 0.025, 0.05, 0.1, 0.5, 0.9, 0.95, 0.975, 0.99, 0.995) df<-c(1:100)
m<-qchisq(x,df[1])
for (i in 2:length(df)) {
  m<-rbind(m,qchisq(x,df[i]))
}

dim(m)<-c(length(df),length(x))

Is there a way to avoid the for loop ?

Thanks Sigbert



R-help@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 Received on Fri Aug 26 22:49:28 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:56 EST