[Rd] cut.Date problem when starting on first day of week (PR#13159)

bolker at zoology.ufl.edu bolker at zoology.ufl.edu
Mon Oct 13 22:30:13 CEST 2008


    Apparently any (?) call of the form

cut(date,"weeks")

where the date *begins the week*, gives the error

Error in 1:(1 + max(which(breaks < maxx))) :
  result would be too long a vector
In addition: Warning message:
In max(which(breaks < maxx)) :
  no non-missing arguments to max; returning -Inf

 To my surprise, this was first reported as a problem in 2006 (!)
(version 2.3.1 (!)), by Mikkel Grum:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/83122.html (17 Aug 2006)
https://stat.ethz.ch/pipermail/r-devel/2008-September/050710.html
https://stat.ethz.ch/pipermail/r-devel/2008-October/050914.html

  In particular, try:

d <- seq.Date(as.Date("2008-07-05"),as.Date("2008-07-08"),by="days")
weekdays(d)

cut(d[1],"weeks") ## OK
cut(d[2],"weeks") ## OK
cut(d[3],"weeks") ## Monday -- breaks
cut(d[4],"weeks") ## OK

cut(d[1],"weeks",start.on.monday=FALSE) ## OK
cut(d[2],"weeks",start.on.monday=FALSE) ## Sunday -- breaks
cut(d[3],"weeks",start.on.monday=FALSE) ## OK
cut(d[4],"weeks",start.on.monday=FALSE) ## OK

  The particular line that fails within cut.Date is

breaks <- breaks[1:(1 + max(which(breaks < maxx)))]

  but I haven't figured out enough about what's going on
to be able to suggest a fix ...

  cheers
    Ben Bolker



More information about the R-devel mailing list