rm(list=ls()) #clears memory setwd("/rstuff") #sets path x <- 1:5000 #number of iterations for "for" chi2 <- NULL #creates null set chi4 <- NULL chi6 <- NULL for(i in seq(along=x)) {chi2<-c(chi2,sum((rnorm(n=2, mean=0, s=1))^2))} #draws 2 standard normal deviates (because mean=0 and s=1) #and calculates sum of the squares for(i in seq(along=x)) {chi4<-c(chi4,sum((rnorm(n=4, mean=0, s=1))^2))} for(i in seq(along=x)) {chi6<-c(chi6,sum((rnorm(n=6, mean=0, s=1))^2))} chid <- cbind(chi2,chi4,chi6) write.csv(chid, file = "chid.csv")