Time spans

Working with Dates and Times in R

Charlotte Wickham

Instructor

Time spans in lubridate

period
  • Human concept of a time span
  • datetime + period of one day =

    same time on the next date

  • variable length
Duration
  • Stopwatch concept of a time span
  • datetime + duration of one day =

    datetime + 86400 seconds

  • fixed number of seconds
Working with Dates and Times in R

Creating a time span

days()
"1d 0H 0M 0S"
days(x = 2)
"2d 0H 0M 0S"
ddays(2)
"172800s (~2 days)"
Working with Dates and Times in R

Arithmetic with time spans

2 * days()
"2d 0H 0M 0S"
days() + days()
"2d 0H 0M 0S"
ymd("2011-01-01") + days()
"2011-01-02"
Working with Dates and Times in R

Functions to create time spans

Time span Duration Period
Seconds dseconds() seconds()
Minutes dminutes() minutes()
Hours dhours() hours()
Days ddays() days()
Weeks dweeks() weeks()
Months - months()
Years dyears() years()
Working with Dates and Times in R

Let's practice!

Working with Dates and Times in R

Preparing Video For Download...