December 2017
Beginner to intermediate
470 pages
12h 29m
English
The random_dates_in_range() function uses the same sample() function we used before, but instead of receiving a list of strings as categories from factor variables, it will receive a list of dates. To generate the full set of valid dates for the simulation, we use the seq() function. This function will generate all values from the start to the end by a specific interval. If we want to generate all odd numbers between 1 and 10, we will use seq(1, 10, 2), which means that it will take 1 and add 2 to it sequentially until 10 is reached. In our case, we want the increment to be a full day, and, conveniently, the seq() function provides this capability when sending date objects by sending the increment as the string ...