Subtract / Add Days from / to Date Object in R (2 Examples)

In this tutorial, I’ll explain how to add or subtract a certain number of days from a date object in R programming.

Example Data

x <- as.Date("2023-01-27")        # Exemplifying Date object
x                                 # Show example date in RStudio console
# [1] "2023-01-27"

Example 1: Subtracting Value from Date in R

x - 50                            # Subtract 50 days from date object
# [1] "2022-12-08"

Example 2: Adding Value to Date in R

x + 50                            # Add 50 days to date object
# [1] "2023-03-18"

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed