R Community of Practice

Week 2

Learning Goals

  1. understand the challenges of working with dates in R
  2. become familiar with the capabilities of the lubridate package
  3. use lubridate to filter and summarize data by date

Challenges of Working with Dates

  • interpreted as strings when imported to R
  • many date formats
  • inconsistent time units (e.g. months, leap years, time zones)

The Data

Scenario: we have a spreadsheet of data tracking research consults from 2018 to 2023. We want to accomplish the following tasks:

  1. Change the date variable to date data type
  2. Summarize the number of consults by year
  3. Summarize consults by month for FY2022

Lubridate Time Spans

  1. durations - measure physical time in seconds
  2. periods – take into account human variations in time due to varying lengths of months, leap years, etc.
  3. intervals – time span defined with a start and end time