Skip to content

problems with seq.dates

2 messages · Ciprian_Marin@ssga.com, Gabor Grothendieck

#
There seem to be a bug in the seq.dates function in the chron package for R
2.0. Please see below:

when the specified frequency is "months", seq.dates does not return the end
of the specified interval all the time:
[1] 05/31/04 06/30/04 07/31/04 08/31/04 09/30/04 10/31/04 11/30/04

Ciprian


Ciprian V Marin
State Street Global Advisors Limited

Authorised and regulated by the Financial Services Authority
Recipient of the Queen's Award for Enterprise 2003

0207 698 6195 (Direct Line)
0207 698 6333 (Main Fax)

Please visit our Web site at www.ssga.co.uk
#
<Ciprian_Marin <at> ssga.com> writes:

: 
: There seem to be a bug in the seq.dates function in the chron package for R
: 2.0. Please see below:
: 
: when the specified frequency is "months", seq.dates does not return the end
: of the specified interval all the time:
: 
: > seq.dates(from = "05/31/04", to = "12/31/04", by = "months")
: [1] 05/31/04 06/30/04 07/31/04 08/31/04 09/30/04 10/31/04 11/30/04
: 


This is a bug.  A workaround is to place the to= date after the 
last date you want in your sequence rather than right at it:

seq.dates(from = "05/31/04", to = chron("12/31/04")+1, by = "months")


You can fix your copy of seq.dates by inserting, after these 3 lines:

    if (by == "months") {
        nxt.day <- month.day.year(as.numeric(from + 1))$month
        end.of.the.month <- frm.mdy$month != nxt.day

the following line:

        if (end.of.the.month) x <- c(x, x[length(x)]+1)