Date and Time—Lubridate

Learn to manipulate date and time data using lubridate.

The lubridate package is popular for working with date and time data. It provides a suite of functions that simplify many everyday operations that data scientists need to perform with date-time data, including re-formatting, calculating intervals, adding periods of time, and converting time zones. With lubridate, working with date and time data can be more accessible, especially when new to R.

In this lesson, we’ll explore the pros and cons of lubridate, use cases for data scientists, and provide examples of key functions and their arguments. We’ll also discuss common issues to be aware of when working with date and time data.

Press + to interact
The lubridate logo
The lubridate logo

Use cases for data scientists

For data scientists, the main benefit of lubridate is that it makes preparing date and time data for analysis intuitive while hiding much of the messiness behind the scenes. Often the date and time data received by data scientists is not ready for analysis and requires significant cleaning. The lubridate package provides much of the standard functionality needed to deal with those situations efficiently and, as such, shows up in a variety of data science applications, for example:

  • Time series analysis: The lubridate package makes coding more efficient when exploring trends and patterns over time.
  • Data visualization: It helps to visualize time series data, such as line charts and heatmaps.
  • Feature engineering: It can extract features from date-time data, such as the day of the week, month, and year, which can then be passed as inputs to analytical models.

However, it should be noted that lubridate is designed mainly to prepare date and time data. It’s not a full suite of tools for time series analysis. If we’re building a complex time series model, lubridate itself will not cover all of the required modeling capabilities—it doesn’t provide the tools to build ARIMA models, for example.

Advantages of lubridate

There are a few ...