R Tutorial: Why lubridate?

Learn lubridate, an R package that makes working with dates and times simple and consistent across different datetime formats. Extract components like month or weekday, calculate durations like reign lengths, and create visualizations such as a joyplot of Auckland's daily temperatures by month.
Chapters
As you've seen, R has some built in support for storing dates and date times, but for the rest of the course, you'll learn about a package called lubridate. Lubridate is designed to make working with dates and times as easy as possible in R. It's a tidyverse package, which means it obeys some key principles, including playing nicely with R's existing datetime objects and being designed for humans, not computers. It also means it will fit nicely in your data analysis pipelines that use other tidyverse tools in particular. In this course, you'll combine lubridate with dplyr and ggplot2 to answer questions about data that includes a date time variable. One nice aspect is that you don't need to worry about whether your date times are stored in date objects, posixct objects, or even time series objects like Zoo or xts. The Lubridate functions will have consistent behavior. You only need to learn one function for any kind of datetime object. You'll start by seeing how easy lubridate makes it to pass a character string into a datetime object. Although R has some built in passing functions, Lubridate functions are simpler to use, more forgiving of different formats, and even allow parsing of many formats in one vector. Then you'll learn about Lubridate functions for extracting and manipulating components of a date time. You'll be able to pull out the month, day of the week, or day of the year from a date time combined with dplyr and ggplot that will allow you to make plots like this joyplot of the maximum daily temperature by month in Auckland. Lubridate also has special objects for handling time spans, the time that passes between two time points. You'll learn how to use time spans to generate sequences of date times and calculate the length of time intervals, like the length of reigns of kings and queens of England. In the final chapter, you'll learn about Lubridate functions for dealing with time zones. Fast Passing of Date times Outputting Date times Ready to get started? I'll see you in the next chapter.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







