How to Add and Subtract Days to and from Date in R ?
R Programming Language provides a variety of ways for dealing with both date and date/time data. The built-in framework as.Date function is responsible for the handling of dates alone, the library chron in R handles both dates and times, without any support for time zones; whereas the POSIXct and POSIXlt classes provide the support for handling datetime objects as well as timezones. Easy conversion of date-time objects can be performed to other date-related objects.
Method 1: Using as.Date() method
The date objects are stored as the number of days calculated starting January 1, 1970, where negative numbers are used to refer to earlier dates. The Date objects support basic arithmetic directly, where in the integers are added or subtracted directly from the Dates. N number of days are added or subtracted directly and the standard date format is returned as an output. The Date object can also specify different formats to contain the dates. The as.Date() method takes as input a string date object and converts it to a Date object.
as.Date(character date object)
The following R snippet illustrates the usage of Date objects :
 "Original Date"  "2020-12-11"  "Subtracted Date"  "2020-12-08"  "Added Date"  "2020-12-14"
Method 2: lubridate package in R
Lubridate is an R package to simulate working easily with dates and time objects. It gives a wide range of functions to perform modifications on the day objects. ymd() method in R is used to extract the Date portion from the date-time object, which is converted into standard years, months, and days formats. days() method accepts an integer as an argument and performs arithmetic on the Date objects using mathematical operators, directly.
Arguments : date – String date object
Returns : Date object in ymd format
 "Original Date"  "2009-10-01"  "Subtracted Date"  "2009-09-25"  "Added Date"  "2009-10-07"
The same arithmetic can also be performed using the days() function in R, which takes as argument the integer value corresponding to the number of days :
 "Original Date"  "2009-10-01"  "Subtracted Date"  "2009-09-25"  "Added Date"  "2009-10-01"