Skip to content

Instantly share code, notes, and snippets.

@rudeboybert
Last active October 31, 2016 15:09
Show Gist options
  • Save rudeboybert/a20029fc7aa0e4af8e1687c12b278ae8 to your computer and use it in GitHub Desktop.
Save rudeboybert/a20029fc7aa0e4af8e1687c12b278ae8 to your computer and use it in GitHub Desktop.
Coin Flipping
# 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