R Data Science 101

My personal, constant learning quest

How to add and subtract Dates and Times in R

Introduction Following the R recipe How to deal with Date and Time in R where we reviewed the base R capabilities to deal with dates and times, we continue exploring how to add and subtract dates and times, also in base R. I plan to cover lubridate and clock packages in the future. Addition of a scalar to a date It’s very common that we need to calculate an end date for a process or service knowing only the starting date and the duration.

How to deal with Dates and Times in R

Introduction A common need that exists in most of the programming languages is parsing strings into dates and converting dates into strings. Mastering this process is of vital importance for data analysts/data scientist because we get data from many different sources and countries where format changes, and for dates this is typically a headache. For instance, “31st of January of 2021” can be written as: 01/31/21: US format January the 31, 2021: US format 31/01/21: typically European format 31.