ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Working with Dates and Times in R

Ver curso

Instrucciones del ejercicio

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

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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

Editar y ejecutar código