R adding days to a date [duplicate] R adding days to a date [duplicate] r r

R adding days to a date [duplicate]


Use +

> as.Date("2001-01-01") + 45[1] "2001-02-15"


You could also use

library(lubridate)dmy("1/1/2001") + days(45)


In addition to the simple addition shown by others, you can also use seq.Date or seq.POSIXt to find other increments or decrements (the POSIXt version does seconds, minutes, hours, etc.):

> seq.Date( Sys.Date(), length=2, by='3 months' )[2][1] "2012-07-25"