Repetition

The function * replicate(nrep, expression) repeats the expression provided nrep times.

e.g. replicate(10, mean(rnorm(100))) reads: ‘draw 100 values from a normal distribution with a mean 0 and sd 1 (the default values), calculate the mean of these 100 values, and do all that 10 times.’


YOUR TURN:
In your local exercise script:
Replicate 1000 times the mean of 10 values drawn from a unifrom distribution between 0 and 10.
Replicate 100 times the mean of 50 values drawn from a normal distribution of mean 10 and standard deviation 5.
Make a histogram of each of your results, are the distributions looking as expected?


Back to top