[Rd] seq improperly increments dates (PR#9120)

Ponzio, Stephen [CIB-LAVA] stephen.ponzio at citigroup.com
Thu Aug 3 17:34:36 CEST 2006


You're right, it's tricky.

I guess I would expect Jan. 30 + 1 month = Feb. 28.

Of couse, then  Jan. 30 + 1 month = Jan. 28 + 1 month;
I understand.

Being that "1 month" is imprecise in terms of number of days,
this anomaly is preferable to skipping months (Jan. 30 + 1 month = March 2),
in my opinion.

That is what I expected, anyway.

Thanks,
Stephen



-----Original Message-----
From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
Sent: Thursday, August 03, 2006 11:24 AM
To: Ponzio, Stephen [CIB-LAVA]
Cc: r-devel at stat.math.ethz.ch; R-bugs at biostat.ku.dk
Subject: Re: [Rd] seq improperly increments dates (PR#9120)


On 8/3/2006 10:26 AM, stephen.ponzio at citigroup.com wrote:
> Full_Name: Stephen Ponzio
> Version: 2.3.1
> OS: Windows
> Submission from: (NULL) (199.67.138.42)
> 
> 
> With the option by="1 month" and a date that is the 31st, 
> the function seq doesn't give the last day of successive months, 
> as I would expect it should:

Why would you expect that?  I'd expect it to give the day 30 days after 
the 1st, and that appears to be what it does.  This doesn't look like a 
bug to me.

I don't understand what logic you would like it to use.  If I ask to 
increment Jan 30 in a non-leap-year by one month, should I get March 2 
(29 days after the 1st of January, as now), February 27 (the day before 
the end of the month), or February 28 (the closest you can get in February)?

Whatever you choose, you'll get anomalies.  Currently it skips months in 
sequences like you show below.  If you try for the same distance from 
the end of the month each time, or truncate to the end of a short month, 
you lose important arithmetic properties:  x - y is not equal to 
(x+1month) - (y+1month).

Duncan Murdoch

> 
>> Sys.Date()
> [1] "2006-08-03"
> 
>> Sys.Date()-3
> [1] "2006-07-31"
> 
> # WORKS OK on Aug. 1:
>> seq(Sys.Date()-2, len=5, by="1 month")
> [1] "2006-08-01" "2006-09-01" "2006-10-01" "2006-11-01" "2006-12-01"
> 
> # DOESN'T WORK on July 31 (list has no date in Sept):
>> seq(Sys.Date()-3, len=5, by="1 month")
> [1] "2006-07-31" "2006-08-31" "2006-10-01" "2006-10-31" "2006-12-01"
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list