CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Working with Dates and Times in R

Afficher le cours

Instructions

  • Create today_8am() by adding a period of 8 hours to today()
  • Create a sequence of periods from one period of two weeks, up to 26 periods of two weeks.
  • Add every_two_weeks to today_8am.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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

Modifier et exécuter le code