add 90 days to a date using lubridate in r

You can easily add days to a date using lubridate library in R.

Assuming you have a date stored in a variable my_date, you can add 90 days to it using the days() function from lubridate:

main.r
library(lubridate)
my_date <- ymd("2021-05-12") # Example date
new_date <- my_date + days(90)
94 chars
4 lines

In the above code, ymd() function from lubridate is used to create a date object from a string ("2021-05-12" in this example) in the year-month-day format. Then, the days() function is used to create a duration of 90 days, which is added to my_date using the + operator. The result is stored in new_date.

You can also use other functions such as weeks(), months(), and years() instead of days() to add a different duration of time to a date.

gistlibby LogSnag