rm(list=ls()) #clears memory setwd("/rstuff") #sets path x <- 1:1000 #number of iterations for "for" pvd <- NULL #creates a null set svd <- NULL smean <- NULL for(i in seq(along=x)) #loops x times {pvd <- c(pvd, ((var(rnorm(n=50, mean=10, sd=2))*(49/50)))-4)} #calculates average squared deviation for 1000 samples of 50 observations from a normal distribution with a mean of 10 #and a standard deviation of 2, and calculates the deviation of that value from the population variance (4) for(i in seq(along=x)) {svd <- c(svd, ((var(rnorm(n=50, mean=10, sd=2))))-4)} #calculates sample standard deviation for 1000 samples of 50 observations from a normal distribution with a mean of 10 #and a standard deviation of 2, and calculates the deviation of that value from the population variance (4) for(i in seq(along=x)) {smean <- c(smean, (mean(rnorm(n=50, mean=10, sd=2))-10))} #calculates sample mean for 1000 samples of 50 observations from a normal distribution with a mean of 10 #and a standard deviation of 2, and calculates the deviation of that value from the population mean (10) bvar <- cbind(pvd,svd,smean)#binds the 4 objects into one object write.csv(bvar, file = "bvar.csv")#prints to a csv file