For your role-playing game, each of your adventurer’s character attributes is calculated as the sum of the scores from three six-sided dice rolls. To save arm-ache, you decide to use R to generate the scores. Below is a helper function three_6d()
to generate them.
Big scores give character bonuses and small scores give character penalties according to the following table:
Score | Bonus |
---|---|
3 | -3 |
4, 5 | -2 |
6 to 8 | -1 |
9 to 12 | 0 |
13 to 15 | +1 |
16, 17 | +2 |
18 | +3 |
Use the three_d6()
function (below) to generate 1000 attribute scores. You should store these in an object called scores
. Next, calculate the frequency of each bonus level in scores
. You should store these frequencies in an object called freqs
. Hint: before creating freqs
you should divide the scores
vector into groups according to the table above.
(from: Cotton, 2013, Learning R, O’Reilly)