Seems changes in r44116 force the interval to be single months (or years) instead of whatever the user specified. I think the attached patches correct this.

Interestingly, 'cut' and 'seq' allow for the 'breaks' specification to be something like "3 months" but the documentation for 'hist' does not allow for this type of specification.

-roger

Gabor Grothendieck wrote:
cut.Date and cut.POSIXt indicate that the breaks argument
can be an integer followed by a space followed by "year", etc.
but it seems the integer is ignored.

For example, I assume that breaks = "3 months" is supposed
to cut it into quarters but, in fact, it cuts it into months as if
3 had not been there.

d <- seq(Sys.Date(), length = 12, by = "month")
cut(d, "3 months")
 [1] 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01 2008-08-01
2008-09-01 2008-10-01 2008-11-01 2008-12-01 2009-01-01 2009-02-01
Levels: 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01
2008-08-01 2008-09-01 2008-10-01 2008-11-01 2008-12-01 2009-01-01
2009-02-01
cut(as.POSIXct(d), "3 months")
 [1] 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01 2008-08-01
2008-09-01 2008-10-01 2008-11-01 2008-12-01 2009-01-01 2009-02-01
Levels: 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01
2008-08-01 2008-09-01 2008-10-01 2008-11-01 2008-12-01 2009-01-01
2009-02-01
cut(as.POSIXlt(d), "3 months")
 [1] 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01 2008-08-01
2008-09-01 2008-10-01 2008-11-01 2008-12-01 2009-01-01 2009-02-01
Levels: 2008-03-01 2008-04-01 2008-05-01 2008-06-01 2008-07-01
2008-08-01 2008-09-01 2008-10-01 2008-11-01 2008-12-01 2009-01-01
2009-02-01

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


--
Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/
diff --git a/src/library/base/R/dates.R b/src/library/base/R/dates.R
index 9496b1d..e69f35c 100644
--- a/src/library/base/R/dates.R
+++ b/src/library/base/R/dates.R
@@ -324,7 +324,7 @@ cut.Date <-
         end <- as.POSIXlt(max(x, na.rm = TRUE))
         end <- as.POSIXlt(end + (31 * 86400))
         end$mday <- 1
-        breaks <- as.Date(seq(start, end, "months"))
+        breaks <- as.Date(seq(start, end, breaks))
     } else if(valid == 4) {
         start$mon <- 0
         start$mday <- 1
@@ -332,7 +332,7 @@ cut.Date <-
         end <- as.POSIXlt(end + (366 * 86400))
         end$mon <- 0
         end$mday <- 1
-        breaks <- as.Date(seq(start, end, "years"))
+        breaks <- as.Date(seq(start, end, breaks))
     } else {
         start <- .Internal(POSIXlt2Date(start))
         if (length(by2) == 2) incr <- incr * as.integer(by2[1])
diff --git a/src/library/base/R/datetime.R b/src/library/base/R/datetime.R
index 95e513f..67cbea2 100644
--- a/src/library/base/R/datetime.R
+++ b/src/library/base/R/datetime.R
@@ -729,7 +729,7 @@ cut.POSIXt <-
         end <- as.POSIXlt(max(x, na.rm = TRUE))
         end <- as.POSIXlt(end + (31 * 86400))
         end$mday <- 1
-        breaks <- seq(start, end, "months")
+        breaks <- seq(start, end, breaks)
     } else if(valid == 7) {
         start$mon <- 0
         start$mday <- 1
@@ -737,7 +737,7 @@ cut.POSIXt <-
         end <- as.POSIXlt(end + (366 * 86400))
         end$mon <- 0
         end$mday <- 1
-        breaks <- seq(start, end, "years")
+        breaks <- seq(start, end, breaks)
     } else {
         if (length(by2) == 2) incr <- incr * as.integer(by2[1])
            maxx <- max(x, na.rm = TRUE)
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to