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

Duncan Murdoch murdoch at stats.uwo.ca
Thu Aug 3 17:23:37 CEST 2006


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