From ggrothendieck at myway.com  Sun Aug  8 03:38:08 2004
From: ggrothendieck at myway.com (Gabor Grothendieck)
Date: Sun Aug  8 03:38:14 2004
Subject: [Rd] sequence of month ends using seq.Date
Message-ID: <loom.20040808T031628-610@post.gmane.org>


It seems that seq.Date starting from month end will always give d days past
the beginning of each month (if the month end of the first month is d days
after the first of that month).  This has the effect of jumping into the
following month for short months. For example, the 3 months after
Jan 31, 2004 are Mar 2, 2004, Mar 31, 2004 and May 1, 2004 according
to seq.Date:

R> seq(as.Date("2004-01-31"), length = 4, by = "month")
[1] "2004-01-31" "2004-03-02" "2004-03-31" "2004-05-01"

In contrast chron uses these rules:

- if the first date is near the end of the month and the sequence
  would otherwise skip a month at any point then use the last day
  of the month, as shown below.

- if the first date is the end of its month then use month ends.  Thus
  starting at Jan 31, 2004 or starting at Feb 29, 2004 would both
  give sequences of month ends.

Here is the calculation using chron:

R> require(chron)
R> seq(chron("01/31/04"), length = 4, by = "month")
[1] 01/31/04 02/29/04 03/31/04 04/30/04

Ideally one would be able to specify to seq.Date whether one wants 
counting done from the beginning of each month (to get the current effect)
or the end of each month (to easily get end of month or second day to the 
end of month sequences, etc.) with reasonable defaults.

(At the moment, workarounds to get end of month sequences
include performing the seq in chron and converting to Date or 
doing a seq relative to the first of the NEXT month and subtracting 
one to get end of month.)


[Rd] sequence of month ends using seq.Date
Gabor Grothendieck