Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Simulating dates within a range

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content