LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Working with Dates and Times in R

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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

Code bearbeiten und ausführen