[Rd] Possible bug in cut.Date()

Martin Becker martin.becker at mx.uni-saarland.de
Wed Dec 20 19:00:00 CET 2006

Dear list,

I suppose that the behaviour of cut.Date() is not as intended for the 
case ' breaks="year" ' (in R 2.4.1 and previous versions):
The corresponding code fragment which defines the first breakpoint in 
this case reads:

        if (valid == 4) {
            start$mon <- 0
            incr <- 366
So the month of the first breakpoint is set to January, but the day of 
month is not set to 1.
This leads to a strange behaviour, see the following example:

 > cut(as.Date(c("2000-01-17","2001-01-13","2001-01-20")),breaks="y")
[1] 2000-01-17 2000-01-17 2001-01-17
Levels: 2000-01-17 2001-01-17

I think, the code fragment above should better read:

        if (valid == 4) {
            start$mon <- 0
            start$mday <- 1
            incr <- 366

(Of course, maybe there are reasons for the current behaviour which I am 
not aware of, and the current behaviour is as intended.)



More information about the R-devel mailing list