shmunde at googlemail.com
2009-Dec-21 12:45 UTC
[Rd] cut.POSIXt problem with breaks= "quarter" (PR#14162)
Full_Name: Qing Xia Version: 2.10.0 OS: Windows XP Submission from: (NULL) (213.71.23.233) I find, when I use "cut" function to cut date-time objects based on breaks "quarter", there exists a problem. It means, if the date-time has "JJJJ-MM-30" or "JJJJ-MM-31", then "cut" runs not correctly, it gives wrong levels. Detail can be found in the following R-Output: 1. correct Output levels, if there is no date-time "JJJJ-MM-30" or "JJJJ-MM-31"> x<- as.Date(c("2009-03-21","2009-03-24")) > cut(x, breaks= "quarter")[1] 2009-01-01 2009-01-01 Levels: 2009-01-01 2. wrong Output levels, if there exists date-time "JJJJ-MM-30" or "JJJJ-MM-31"> x<- as.Date(c("2009-03-21","2009-03-30")) > cut(x, breaks= "quarter")[1] 2009-01-01 2009-01-01 Levels: 2009-01-01 2009-04-01> x<- as.Date(c("2009-03-21","2009-03-31")) > cut(x, breaks= "quarter")[1] 2009-01-01 2009-01-01 Levels: 2009-01-01 2009-04-01
Gabor Grothendieck
2009-Dec-21 17:37 UTC
[Rd] cut.POSIXt problem with breaks= "quarter" (PR#14162)
as.yearqtr in the zoo package could be used as a workaround until cut is fixed.> as.yearqtr(as.Date(c("2009-03-21","2009-03-31")))[1] "2009 Q1" "2009 Q1"> as.Date(as.yearqtr(as.Date(c("2009-03-21","2009-03-31"))))[1] "2009-01-01" "2009-01-01" On Mon, Dec 21, 2009 at 7:45 AM, <shmunde at googlemail.com> wrote:> Full_Name: Qing Xia > Version: 2.10.0 > OS: Windows XP > Submission from: (NULL) (213.71.23.233) > > > I find, when I use "cut" function to cut date-time objects based on breaks > "quarter", there exists a problem. It means, if the date-time has "JJJJ-MM-30" > or "JJJJ-MM-31", then "cut" runs not correctly, it gives wrong levels. Detail > can be found in the following R-Output: > > 1. correct Output levels, if there is no date-time "JJJJ-MM-30" or "JJJJ-MM-31" > >> x<- as.Date(c("2009-03-21","2009-03-24")) >> cut(x, breaks= "quarter") > [1] 2009-01-01 2009-01-01 > Levels: 2009-01-01 > > > 2. wrong Output levels, if there exists date-time "JJJJ-MM-30" or "JJJJ-MM-31" > >> x<- as.Date(c("2009-03-21","2009-03-30")) >> cut(x, breaks= "quarter") > [1] 2009-01-01 2009-01-01 > Levels: 2009-01-01 2009-04-01 > > >> x<- as.Date(c("2009-03-21","2009-03-31")) >> cut(x, breaks= "quarter") > [1] 2009-01-01 2009-01-01 > Levels: 2009-01-01 2009-04-01 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Prof Brian Ripley
2009-Dec-23 10:23 UTC
[Rd] cut.POSIXt problem with breaks= "quarter" (PR#14162)
What exactly is the purported bug here? It seems to me that the cuts are correct and the behaiour is as documented, but that you were not expecting empty levels. If that bothers you, use cut(x, breaks= "quarter")[,drop=TRUE] On Mon, 21 Dec 2009, shmunde at googlemail.com wrote:> Full_Name: Qing Xia > Version: 2.10.0 > OS: Windows XP > Submission from: (NULL) (213.71.23.233) > > > I find, when I use "cut" function to cut date-time objects based on breaks > "quarter", there exists a problem. It means, if the date-time has "JJJJ-MM-30" > or "JJJJ-MM-31", then "cut" runs not correctly, it gives wrong levels. Detail > can be found in the following R-Output: > > 1. correct Output levels, if there is no date-time "JJJJ-MM-30" or "JJJJ-MM-31" > >> x<- as.Date(c("2009-03-21","2009-03-24")) >> cut(x, breaks= "quarter") > [1] 2009-01-01 2009-01-01 > Levels: 2009-01-01 > > > 2. wrong Output levels, if there exists date-time "JJJJ-MM-30" or "JJJJ-MM-31" > >> x<- as.Date(c("2009-03-21","2009-03-30")) >> cut(x, breaks= "quarter") > [1] 2009-01-01 2009-01-01 > Levels: 2009-01-01 2009-04-01 > > >> x<- as.Date(c("2009-03-21","2009-03-31")) >> cut(x, breaks= "quarter") > [1] 2009-01-01 2009-01-01 > Levels: 2009-01-01 2009-04-01 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595