If you are looking for a simulation, you can first implement a function that simulates throwing the dice until you get the expected result:
intentos <- function(resultado_buscado) {
i <- 1
while (!(sample(1:6,size=1)==resultado_buscado)) {
i <- i + 1
}
return (i)
}
The previous function will generate a random result among the 6 possible ones and will repeat the cycle until obtaining the value that we are looking for.
Then we can repeat the procedure the n
times we want, for this we can use an implicit loop with sapply()
, finally with table()
we will generate the frequency table
table(sapply(1:10000, function(x) {intentos(6)}))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1665 1417 1127 1019 833 654 567 437 376 323 254 228 192 161 125
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
123 81 61 61 54 36 32 27 28 20 20 13 14 10 6
31 33 34 35 36 37 38 41 42 44 46 47 52 61
9 6 1 3 4 2 2 1 3 1 1 1 1 1