knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(dieroller)
The package "dieroller" is a minimal implementation for simulating rolling
a die a given number of times, and to visualize the relative frequencies
in such a series of rolls
dieThe first step is to create a "die" object with the function die():
mydie <- die() mydie
By default, die() creates a fair standard die with six sides numbered 1, 2, 3, 4, 5, and 5, and with probability values for each side of 1/6.
You can change the defatuls with arguments sides and prob:
loaded <- die(prob = c(0.1, 0.1, 0.2, 0.2, 0.35, 0.05)) loaded
Once you have defined a "die" object, you can use the function roll() to
roll a die a given number of times. The output will be an object of class
"roll", which will contain the vector of rolls:
rolls100 <- roll(mydie, times = 100) rolls100
The summary() function gives you a nice table of frequencies:
summary(rolls100)
You can use the function plot() to create a graohic with the relative
frequencies of a series of coin tosses:
plot(rolls100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.