In this second lesson of our course on strings, dates and times in R, you'll learn the fundamentals of working with dates and times in R.

Dates and times appear everywhere in an analysis context. Businesses want to see if a new advertising campaign has made a significant effect on their sales, so they would look for patterns before and after the campaign. Accelerometers in your phone keep track of your activity through time, so you can analyze how active you are throughout the day.

R doesn't have a built-in data type for dates and times, but it has well established functions that smooth the process of using them. Throughout this lesson, we'll be using the lubridate package.

In the lesson, you'll learn how dates and times are represented in Unix, how to extract a particular component from a datetime, how to calculate timespans and durations, and how to manipulate timezones.

By the end of this lesson, you'll be comfortable with the fundamentals required to work with dates and times effectively in R.


  • Learn to use the lubridate package to work with dates and times.
  • Calculate timespans, durations, etc.
  • Manipulate timezones using R.

Lesson Outline

  1. Introduction
  2. Data Representation
  3. Time Representation
  4. Unix Representation
  5. Component Extraction
  6. Time Span Calculations
  7. Durations and Periods
  8. Time Zone Manipulation
  9. Next Steps