Riddler: Simulating a Week of Rain

Simulation

Published

December 11, 2018

Notable topics: Simulation

Recorded on: 2018-12-11

Timestamps by: Alex Cookson

View code

Screencast

Timestamps

crossing

Using crossing function to get all combinations of specified variables (100 trials of 5 days)

rbinom

Using rbinom function to simulate whether it rains or not

ifelse

Using ifelse function to set starting number of umbrellas at beginning of week

Explanation of structure of simulation and approach to determining number of umbrellas in each location

Changing structure so that we have a row for each day's morning or evening

group_byifelserow_number

Using group_by, ifelse, and row_number functions to set starting number of umbrellas for each trial

case_when

Using case_when function to returns different values for multiple logical checks (allows for more outputs than ifelse)

cumsum

Using cumsum function to create a running tally of number of umbrellas in each location

Explanation of output of simulated data

Using any function to check if any day had a negative "umbrella count" (indicating there wasn't an umbrella available when raining)

Asking, "When was the first time Louie got wet?"

Creating a custom vector to convert an integer to a weekday (e.g., 2 = Tue)