rm(list=ls()) #clears memory setwd("/rstuff") #sets path x <- 1:5000 #number of iterations for "for" smeen <- NULL #creates null set popdif <- NULL meendif <- NULL for(i in seq(along=x)) {smeen<-c(smeen, mean(runif(100,1,10)))}#randomly draws 100 continuous numbers #from 1 to 10, and calculates the mean #a2 <- sample(1:10, 500, replace=T) would draw discrere observations #replace=T specifies sampling with replacement; replace=F is without replacement for(i in seq(along=x)) {popdif<-c(popdif, (mean(runif(100,1,10)))-(mean(smeen)))} for(i in seq(along=x)) {meendif<-c(meendif, (mean(runif(100,1,10)))-(mean(runif(100,1,10))))} mndif <- cbind(smeen,popdif,meendif) write.csv(mndif, file = "mndif.csv")