Skip to content
Prev 126401 / 398500 Next

Dice simulation: Getting rep to re-evaluate sample()?

rep(
    sum(sample(1:6,100,replace=T)),
    times=10)

Read carefully what you wrote.  You asked R to sum a single sample, then
make
ten copies of the sum.

You need to take ten samples, then sum each.   apply() would be helpful.

-----Original Message-----
I'm trying to get R to simulate the sum of the values on 10 fair dice
(yes, it's related to a homework problem, but is not the problem
itself). I tried to do this:
[1] 341 341 341 341 341 341 341 341 341 341