Last active
October 31, 2016 15:09
-
-
Save rudeboybert/a20029fc7aa0e4af8e1687c12b278ae8 to your computer and use it in GitHub Desktop.
Coin Flipping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load packages, including mosaic package | |
library(dplyr) | |
library(ggplot2) | |
library(mosaic) | |
# Flip a coin once. Try this multiple times: | |
rflip() | |
# Flip a coin 10 times. Try this multiple times: | |
rflip(10) | |
# Flip a coin 10 times, but do this 5 times. Try this multiple times | |
do(5) * rflip(10) | |
# Flip a coin 10 times, but do this 500 times | |
do(500) * rflip(10) | |
# Gah! There are too many rows! | |
simulations <- do(500) * rflip(10) | |
# Convert to data frame format; this allows us to better view in console | |
simulations <- simulations %>% | |
as_data_frame() | |
# We could also View() it | |
View(simulations) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment