Source code in support of the LinkedIn Learning course "R Programming in Data Science: Dates and Times"
Introduction | ||
---|---|---|
Calculating Times and Dates with R | Learn why Dates and Times are important concepts in data science. | |
1. Why are Dates and Times in R Confusing? |
|
|
Typical date calculations | Learn how to recognize when to use date and time operators | |
| How dates and times are stored in R | Learn what the Date object contains and how this is useful. |
| Choose the right Date and Time tool | Learn how to select the best date or time tool for a particular application. |
2. Dates and Times in Base R |
|
|
| The Base R "Date" Class | Base R provides a small set of functions and classes for dates and times, but how can they be used to best advantage? Gain an understanding of tools available in Base R for the manipulation of Times and Dates. |
| Use formatters to recognize dates in character strings | Learn how to specify the position of years, months, days, hours, minutes, and seconds. |
| Dealing with timezones and daylight savings time | Learn about using the tz parameter in the as.POSIXct( ) function. |
| Use operators to compare date objects | Learn how to determine if one time is greater-than, less-than, or equal to another date or time. |
| Adding and Subtracting Dates and Times | Learn how to use difftime to store the interval between two dates. |
| Create sequences of dates, cut dates, and round dates | Learn about seq.Date(), cut.Date(), and round.Date() |
| Extract parts of a date | Learn how to obtain the hour, minutes, and more from a Date object. |
| Presenting formatted dates and times | We talk about dates in different ways, randomly mixing day of the month, month name, day of the week and everything else. R provides configurable tools to express this in whatever way necessary. |
| use read.csv() to import csv date information | Learn how to use colClasses = Date for POSIXct and POSIXlt. |
3. Lubridate and the Tidyverse |
|
|
| Advantages of the Lubridate package | Learn how lubridate combines several date functions in a coherent flow. |
| Parsing date and time with Lubridate | Learn about ymd_hms(), today(), now() and other functions. |
| Getting and Setting time components with Lubridate | Learn about date(), year(), and other functions that set parts of a date. |
| Rounding dates and time with lubridate | Learn how to use floor, round, and ceiling to manipulate dates. |
| Lubridate math with durations | Recording time requires a way to record how long an event takes, regardless of when it starts or stops. For this, Lubridate provides durations |
| Lubridate math with periods | Time marches on, but human time starts and stops. The calendar doesn't accurately line up with leap years and the phase of the moon. For this, lubridate provides periods. |
| Lubridate math with intervals | Some time intervals start and stop at certain times - my current age, for example. For this, lubridate provides the interval class. |
| Time zones with Lubridate | Learn how to use UTC and other time zone names to adjust time to a locale. |
4. Dates and Times for Business and Finance |
|
|
| The "busdater" package | Learn how to get a current financial year, start and end of current month, or start and end of financial year. |
| The "businessDuration" package | Learn how to calculate business duration between two dates. |
| The "fmdates" package | Learn how to check if dates are business days in certain locales and adjust date calculations. |
5. Working with time-series data |
|
|
| Time-series data | Learn three key differences between the two types of data. |
| The base R "ts" class | Learn how to create time-series data, manipulate it, and plot it. |
| The "zoo" package | Learn how the zoo package is unique and when to use it. |
| The "xts" package | Learn about subsetting a dataframe by date. |
| The "tsibble" and "tibbletime" packages | Learn how this tidyverse object provides time-based subsetting, aggregating by time, and time groups. |
| Tme series rolling statistics | Learn about moving averages, trend analysis, ARMA and ARIMA |
| Time series graphics | Learn how to use plot.ts, plot.xts, and plot.zoo. |
| The "timelineR" package | Learn how to use plot-timeline() to easily create timelines of time-series data. |
| The "timelineS" package | Learn to use timelineG() and timelineS() to plot advanced graphs of time-series data. |
| The CRAN Task View for Time Series Analysis | Learn where to find tutorials, examples, and resources for working with Time-Series data. |
6. Specialized Date and Time packages |
|
|
| The "anytime" package | Learn when anytime is the best tool for date time conversion into POSIXct. |
| The "hms" package | Learn how to use parse_hms() to create difftime objects from character vectors. |
| The "mondate" package | Learn how to use mondate to calculate dates in terms of months |
| The "datetime" package | Learn how datetime provides simplified handling of date time conversion. |
| The "datetimeutils" package | Learn how to use datetimeutils to select days of the week, format timestamps for RSS, and convert dates to MATLAB and Excel. |
| The "padr" package | Learn how to deal with time-series over-plotting and missing data. |
Conclusion |
|
|
| Next steps |
|