Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R adding days to a date [duplicate]

Tags:

date

datetime

r

I have a date that I would like to add days to in order to find some future date.

for instance how would I find the date that is 45 days after 1/1/2001?

like image 546
screechOwl Avatar asked Apr 25 '12 18:04

screechOwl


People also ask

How do you add days in R?

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. Code: R.

Can you add and subtract dates in R?

If you have an object of class “Date” like systems date, you can add or subtract days in R by simply adding or subtracting 1.

How do I calculate the number of days between two dates in R?

Calculate Time Difference between Dates in R Programming – difftime() Function. difftime() function in R Language is used to calculate time difference between dates in the required units like days, weeks, months, years, etc.

Can we subtract dates in R?

A vector of dates has been created for you. You can use subtraction to confirm that January 1, 1970 is the first date that R counts from. First, create a variable called origin containing "1970-01-01" as a date. Now, use as.


1 Answers

Use +

> as.Date("2001-01-01") + 45 [1] "2001-02-15" 
like image 127
Andrie Avatar answered Sep 21 '22 13:09

Andrie