Skip to content
Prev 2834 / 15274 Next

Relative Date Question

Here are a couple of possibilities.

library(zoo) # as.yearmon, as.Date.yearmon

# test data
x <- seq(as.Date("2000-02-01"), by = "month", length = 6)-1
x

# use same number of days past start of next month
ans1 <- as.Date(as.yearmon(x) + 1/12) + as.numeric(format(x, "%d")) - 1
ans1

# or if you don't want to go beyond the end of the next month:
pmin(ans1, as.Date(as.yearmon(x) + 2/12)-1)
On Thu, Aug 28, 2008 at 8:02 AM, Peter Carl <peter at braverock.com> wrote: