Benjamin Telkamp Benjamin Telkamp - 1 year ago 77
R Question

Sampling Distribution from a data-set with one column

I want to create a sampling distribution for a mean. I have a variable

with at least ten thousand values. I want take 500 samples (n=10) and then show the distribution of the sample means in a histogram. I think it worked with the following, but can anyone check if this is what i meant and tell me what the
within the apply function stands for?

x <- rnorm(10000, 7.5, 1.5)
draws = sample(x, size = 10 * 500, replace = TRUE)
draws = matrix(draws, 10)
drawmeans = apply(draws, 2, mean)

would be sincerely appreciated!

Answer Source

You could do this using replicate if you wanted. One of lots of different ways. For data frame df

out = replicate(500, mean(sample(df$Scores,10)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download