[Rd] bug in cut.Date() (PR#9433)

From: <martin.becker_at_mx.uni-saarland.de>
Date: Fri 29 Dec 2006 - 10:53:55 GMT


Full_Name: Martin Becker
Version: 2.4.1
OS: WinXP/Linux
Submission from: (NULL) (134.96.96.42)

When using cut.Date() with 'breaks="year"', the month of the breakpoints is properly 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 asked on R-devel (2006-12-20), if there are reasons for this (in my opinion strange) behaviour, but since I got no answer, I suppose this behaviour is not intended and thus there is a bug in cut.Date().

The corresponding code fragment which defines the first breakpoint in the case 'breaks="year"' reads (2.4.1, 2.4.1 patched, 2.5.0):

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

I think, the code fragment above should better read:

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

The following patch to src/library/base/R/dates.R should do this change:

301c301
< if(valid == 4) { start$mon <- 0; incr <- 366 }

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

Kind regards,

  Martin

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Dec 29 21:55:54 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 29 Dec 2006 - 22:31:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.