Skip to content
Prev 44447 / 398526 Next

How to repeat a procedure

On Wed, 18 Feb 2004, Haiyan Chen wrote:

            
YOu can do this without the loop, eg

x3<-rpois(50*100, rep(mu,each=100))
x3<-ifelse(runif(50*100)<0.01, 0, x3)
x3<-matrix(x3, ncol=50)
means<-apply(x3,2,mean)
vars<-apply(x3,2,var)
cbind(means,vars)
make.a.matrix<-function(...){
	x3<-rpois(50*100, rep(mu,each=100))
	x3<-ifelse(runif(50*100)<0.01, 0, x3)
	x3<-matrix(x3, ncol=50)
	cbind(apply(x3,2,mean), apply(x3,2, var))
}

many.matrices<-lapply(1:500, make.a.matrix)

gives a list of 500 matrices.  This isn't quite the most efficient
solution, but it's not bad.


	-thomas