Reputation: 3
I am running a simulation on rolling dice I stored on die roll
dieRolls <- sample(1:6,5000, replace = TRUE)
In order to simulate two dice being rolled we utilize the replicate function to simulate rolling two dice
replicate(2,dieRolls)
TwoRolledDiceSample <- replicate(2,dieRolls)
Now I need to create a table of the sums of the two dice and utilizing
table(TwoRolledDiceSample)
Only returns the number of time a 1:6 was rolled. Any help will be greatly appreciated as I am a first time learner
Upvotes: 0
Views: 460
Reputation: 942
In your code you only roll once and then copy that results, that is not simulating 2 dice.
try:
dieRolls <- replicate(2,sample(1:6,5000, replace = TRUE))
TwoRolledDiceSample <- as.data.frame(dieRolls)
TwoRolledDiceSample$sum = TwoRolledDiceSample$V1 + TwoRolledDiceSample$V2
and then
table(TwoRolledDiceSample$sum )
Upvotes: 0