Skip to content
Prev 44455 / 398526 Next

How to repeat a procedure

Haiyan Chen wrote:

            
Try:

mean.var<-function(n=10, m=5){
 mu<-(1:n)^2
 x<-matrix(rpois(n*m,mu),n,m)
 stat<-t(apply(x,1,function(x)c(mean(x),var(x))))
}

to set some elements of x to zero you can add an additional line in mean.var
n<-100; m<-50
n.comp<-500
for(i in 1:n.comp) 
eval(parse(text=paste("result",i,"<-mean.var(n,m)",sep="")))


Peter