# create an empty variable called sample.data sample.data = NA # create an empty variable called sample.means sample.means = NA # create an empty variable called sample.vars sample.vars = NA # this is a structure called a for loop. it loops through the commands between # the brackets {} as many times are specified. # in this case, the first command makes a random sample of data, sample.data # that has 5 values, a mean of 300, and a standard deviation of 25 # it then makes the mean of the sample, and stores it in sample.means # when the loop is done there will be 1000 means of 1000 samples. # the same thing is done for variance. for (counter in 1:1000) { sample.data = rnorm(5,300,25) sample.means[counter] = mean(sample.data) sample.vars[counter] = var(sample.data) } # set up a side by side plot par(mfrow=c(2, 2)) par(mar=c(1,1,1,1)) # plot the sample means plot(sample.means,ylim = c(275,325)) # histogram the sample means hist(sample.means) # plot the sample variances plot(sample.vars,ylim = c(1,2000)) # histogramt the sample variances hist(sample.vars)