Introduction to dates

Working with Dates and Times in R

Charlotte Wickham

Instructor

Dates

Different conventions in different places

27th Feb 2013

  • NZ: 27/2/2013
  • USA: 2/27/2013
Working with Dates and Times in R

The global standard numeric date format

1 https://xkcd.com/1179/
Working with Dates and Times in R

ISO 8601 YYYY-MM-DD

  • Values ordered from the largest to smallest unit of time
  • Each has a fixed number of digits, must be padded with leading zeros
  • Either, no separators for computers, or - in dates
  • 1st of January 2011 -> 2011-01-01
Working with Dates and Times in R

Dates in R

2003-02-27
1974
"2003-02-27"
"2003-02-27"
str("2003-02-27")
chr "2003-02-27"
as.Date("2003-02-27")
"2003-02-27"
str(as.Date("2003-02-27"))
Date[1:1], format: "2003-02-27"
  • Packages that import dates: readr, anytime
Working with Dates and Times in R

Let's practice!

Working with Dates and Times in R

Preparing Video For Download...