Generating sequences of datetimes
By combining addition and multiplication with sequences you can generate sequences of datetimes. For example, you can generate a sequence of periods from 1 day up to 10 days with,
1:10 * days(1)
Then by adding this sequence to a specific datetime, you can construct a sequence of datetimes from 1 day up to 10 days into the future
today() + 1:10 * days(1)
You had a meeting this morning at 8am and you'd like to have that meeting at the same time and day every two weeks for a year. Generate the meeting times in this exercise.
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
- Create
today_8am()
by adding a period of 8 hours totoday()
- Create a sequence of periods from one period of two weeks, up to 26 periods of two weeks.
- Add
every_two_weeks
totoday_8am
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add a period of 8 hours to today
today_8am <- today() + ___
# Sequence of two weeks from 1 to 26
every_two_weeks <- ___
# Create datetime for every two weeks for a year