ddply seems to have difficulty with POSIXct. Here is an example (based
on my initial problem, which was using ddply to get ranges of
dates based on a grouping variable. I have omitted a grouping variable here)
try1<-structure(c(-2208988800, -2206310400, -2203891200, -2201212800,
-999475200, -996796800, -994204800, -991526400), class = c("POSIXct",
"POSIXt"), tzone = "UTC")
try1 # all whole dates
# Like try1, but 10-second change to first element
try1a<-structure(c(-2208988800-10, -2206310400, -2203891200, -2201212800,
-999475200, -996796800, -994204800, -991526400), class = c("POSIXct",
"POSIXt"), tzone = "UTC")
try1a[1:4] # 10 second change in first element...
# Like try1, but different class
try2<-structure(c(-25567, -25536, -25508, -25477, -11568, -11537, -11507,
-11476), class = "Date")
all.equal(as.Date(try1),try2)
# put into data frames for ddply use
x1<-data.frame(try1)
x1a<-data.frame(try1a)
x2<-data.frame(try2)
# base R results. These are correct
range(x1$try1)
range(x1a$try1a) # 10 second diff. 1st element is the minimum
range(x2$try2)
# But ...
ddply(x1,.(),function(dfr) range(dfr[,1])) # off by 5 or 4 hours
ddply(x1a,.(),function(dfr) range(dfr[,1])) # delta of 10 secs in min, so delta is correct
ddply(x2,.(),function(dfr) range(dfr[,1])) # OK
# as.Date "corrects" this
ddply(x1,.(),function(dfr) range(as.Date(dfr[,1])))
# and see individual returns values
(test1<-ddply(x1,.(),function(dfr) dfr[1]) )
all.equal(x1,test1[2]) # OK
# But this does not work
ddply(x1,.(),function(dfr) dfr[,1]) # off by 5 or 4 hours
Ideas?
Joe Voelkel