Re: [Rd] forwarded: bug (?) in cut.POSIXt with breaks=integer

2009-10-17 Thread Vitalie S.

On Fri, 16 Oct 2009 16:12:40 +0200, Ben Bolker bol...@ufl.edu wrote:



PS a parallel problem seems to occur in cut.Date  ... cut.POSIXt and  
cut.Date

both allow
breaks to be a single integer specifying the number of breaks, and both  
call


 if(is.null(labels)) levels(res) - as.character(breaks[-length(breaks)])
near the end of the function, which breaks (so to speak) if
length(breaks)!=length(levels(res))-1

I could keep working on a patch if requested, but probably won't  
otherwise.


I believe it's an important issue. In plotting long time series grouping  
is indispensable.

Thank you, Ben, for working on that.

May I take this opportunity and propose an additional argument by to  
cut function. This would make cut similar to seq and cut.POSIXt (in the  
latter, intervals as 30 s are allowed in breaks specification).  
Conceptually it's often simpler to think in terms of the length of  
interval than the number of intervals in breaks.


Thanks,
Vitalie.


  Ben Bolker








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


Re: [Rd] forwarded: bug (?) in cut.POSIXt with breaks=integer

2009-10-17 Thread Gabor Grothendieck
That is usually done with trunc rather than cut since in the case of a
time series we normally don't want a factor result (which is what cut
would give):

trunc(tt, secs)
trunc(tt, mins)
# etc

trunc.POSIXt does not support the 30 secs syntax but trunc.times in
the chron package supports similar functionality:

library(chron)
trunc(as.chron(format(tt)), 00:00:30)

# or relative to GMT
trunc(as.chron(tt)), 00:00:30)

On Thu, Oct 15, 2009 at 1:10 PM, Ben Bolker bol...@ufl.edu wrote:

 From: Vitalie S. vitosmail at rambler.ru
 Subject: Bug in cut.POSIXt
 Newsgroups: gmane.comp.lang.r.general
 Date: 2009-10-15 15:47:48 GMT (1 hour and 29 minutes ago)

 Hello Everyone,

 Before reporting decided to post here first:

 tt - structure(c(1254238817, 1254238859, 1254238969, 1254239080), class =
 c(POSIXt,
                                                              POSIXct),
 tzone = )

 cut.POSIXt(tt, 2)
 #Error in `levels-.factor`(`*tmp*`, value = character(0)) :
 #  number of levels differs

 cut.POSIXt(tt, 2, labels=c(a1, a2))
 #[1] a1 a1 a2 a2
 #Levels: a1 a2

 cut(tt, 2 mins)
 #[1] 2009-09-29 17:40:00 2009-09-29 17:40:00 2009-09-29 17:42:00
 2009-09-29 17:44:00
 #Levels: 2009-09-29 17:40:00 2009-09-29 17:42:00 2009-09-29 17:44:00

 sessionInfo()
 R version 2.9.2 Patched (2009-09-24 r50069)
 i386-pc-mingw32

 locale:
 LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
 States.1252;LC_MONETARY=English_United
 States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

 attached base packages:
 [1] stats     graphics  utils     datasets  grDevices methods   base


 Vitalie.


 ==

  I would agree that this is a bug ... this patch gets rid of the error,
 but leaves the labels very ugly -- given enough hours I might be able to
 figure out how to make the labels nice, but someone else can probably do
 it quicker (see comments in code below)


  It would probably also be worth adding something like

 cut(Dates,2)

  around line 5067 of reg-tests-1.R


 --- datetime.R  2009-10-15 13:01:15.0 -0400
 ***
 *** 764,770 
        }
      } else stop(invalid specification of 'breaks')
      res - cut(unclass(x), unclass(breaks), labels = labels, right =
 right, ...)
 !     if(is.null(labels)) levels(res) -
 as.character(breaks[-length(breaks)])
      res
  }

 --- 764,782 
        }
      } else stop(invalid specification of 'breaks')
      res - cut(unclass(x), unclass(breaks), labels = labels, right =
 right, ...)
 !     if(is.null(labels)) {
 !       if (is.numeric(breaks)  length(breaks) == 1L)
 !         levels(res) - as.character(breaks[-length(breaks)])
 !       } else {
 !         ## ?? what should happen here?
 !         ## this version simply leaves the break values
 !         ## as numeric (and very ugly)
 !         ## I don't know how to safely convert the breakpoints
 !         ## back to a character format (e.g.
 !         ## levels(res) = [1970-01-01 00:00:00,1970-01-01 12:00:00)
 !         ## instead of [18000,61200)
 !       }
 !     }
      res
  }


 --
 Ben Bolker
 Associate professor, Biology Dep't, Univ. of Florida
 bol...@ufl.edu / www.zoology.ufl.edu/bolker
 GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc


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



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


Re: [Rd] forwarded: bug (?) in cut.POSIXt with breaks=integer

2009-10-16 Thread Ben Bolker

PS a parallel problem seems to occur in cut.Date  ... cut.POSIXt and cut.Date
both allow
breaks to be a single integer specifying the number of breaks, and both call

 if(is.null(labels)) levels(res) - as.character(breaks[-length(breaks)])
  
near the end of the function, which breaks (so to speak) if
length(breaks)!=length(levels(res))-1

I could keep working on a patch if requested, but probably won't otherwise.

  Ben Bolker






-- 
View this message in context: 
http://www.nabble.com/forwarded%3A-bug-%28-%29-in-cut.POSIXt-with-%22breaks%22%3Dinteger-tp25914604p25926126.html
Sent from the R devel mailing list archive at Nabble.com.

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