The CRAN time series task view gives an overview of the R packages that deal with dates and times, particularly for time series analysis.
This 2014 blogpost on Using Dates and Times in R describes several common classes of dates, summarized here:
- Date: if you have only dates, but no times, in your data
- POSIXct (calendar time): if you have times in your data, this is usually the best class to use
- POSIXlt (local time, lists): enables easy extraction of specific componants of a time
- chron: good option when you don’t need to deal with timezones or daylight savings
- lubridate: a wrapper for POSIXct with more intuitive syntax (cheatsheet here)
- distinguishes between four types of objects: instants, intervals, durations, and periods. An instant is a specific moment in time. Intervals, durations, and periods are all ways of recording time spans
NEON has a tutorial series that works through various time types, and includes sample datasets for us to use.
The package tibbletime was developed for business/finance, but was specifically built to work well with the tidyverse
.
Data packages on the Arctic Data Center:
- Plot net ecosystem exchange (NEE) from Kangerlussuaq (2012 - 2014 growing seasons)
- Agashashok Climate Data
Miscellaneous datasets:
- Seinfeld episodes (date only) 📺
- Chicago taxi trips 🚕
- Seattle library data 📚
- Stock market records 💰
Top resources:
- lubridate cheatsheet & R for Data Science chapter on dates/times
- tibbletime package
filter_time()
succinctly filters a tbl_time object by date:filter_time('2013-03' ~ '2015')
as_period()
- converts a tbl_time object from daily to monthly, from minute data to hourly, and morerollify()
- modifies a function so that it calculates a value (or a set of values) at specific time intervals. For example, for a moving average:rollify(mean, window = 5)
- NEON tutorial series - starts off in base R and introduces tidyverse methods in 04; discusses methods for subsetting and plotting by date