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
Seems it did work as advertised in R 2.6.0 but is still broken in R-devel. Will take a look. -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 at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/
I am using [1] "R version 2.6.2 alpha (2008-01-26 r44181)" and also get the same under: "R version 2.7.0 Under development (unstable) (2008-03-13 r44752)" On Tue, Mar 18, 2008 at 2:09 PM, Roger D. Peng <rpeng at jhsph.edu> wrote:> Seems it did work as advertised in R 2.6.0 but is still broken in R-devel. Will > take a look. > > -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 at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > -- > Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/ >
By the way, it would be nice if the breaks argument accepted the word "quarter" directly since its quite a common break to need when using dates. On Tue, Mar 18, 2008 at 2:29 PM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> I am using > > [1] "R version 2.6.2 alpha (2008-01-26 r44181)" > > and also get the same under: > > "R version 2.7.0 Under development (unstable) (2008-03-13 r44752)" > > > On Tue, Mar 18, 2008 at 2:09 PM, Roger D. Peng <rpeng at jhsph.edu> wrote: > > Seems it did work as advertised in R 2.6.0 but is still broken in R-devel. Will > > take a look. > > > > -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 at r-project.org mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > > > > -- > > Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/ > > >
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 at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/ -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch-dates.R Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20080318/46ce1eaf/attachment.pl -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch-datetime.R Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20080318/46ce1eaf/attachment-0001.pl