# NOT RUN {
# characters will be coerced to Date
AddMonths("2013-01-31", 1)
# negative n
AddMonths(as.Date("2013-03-31"), -1)
# Arguments will be recycled
# (with warning if the longer is not a multiple of length of shorter)
AddMonths(c("2013-01-31", "2013-03-31", "2013-10-31", "2013-12-31"), c(1,-1))
x <- as.POSIXct(c("2015-01-31", "2015-08-31"))
n <- c(1, 3)
AddMonths(x, n)
# mind the origin if x supplied as numeric ...
x <- as.numeric(as.Date(x))
AddMonths(x, n, origin=as.Date("1970-01-01"))
# }
Run the code above in your browser using DataLab