[R-SIG-Finance] aggregate over POSIX timestamps not returning unique values

Markus Loecher markus at insightfromdata.com
Thu Feb 28 21:11:09 CET 2008


I am puzzled by the following observation. It seems that aggregating 
over POSIX timestamps sometimes returns duplicate entries in the output.
For example:

tmp <- zoo(cumsum(rnorm(35041)), order.by = 
seq(as.POSIXct("2007-01-01 10:00:00"), to = as.POSIXct("2008-01-01 
10:00:00"), by = 15*60))
  plot(tmp)
  tmp.h <- aggregate(coredata(tmp), by = 
list(as.POSIXct(trunc(index(tmp),"hour"))), FUN = mean)
  plot(zoo(tmp.h[,2], as.POSIXct(as.character(tmp.h[,1]))))

 > Warning message:
 > some methods for "zoo" objects do not work if the index entries 
in >'order.by' are not unique in: zoo(tmp.h[, 2], as.POS...

When I use the more elegant aggregate.zoo() version of this, the 
problem is a non issue:

tmp.h <- aggregate(tmp, by = as.POSIXct(trunc(index(tmp),"hour")), FUN = mean)

I would still l like to understand this, any help would be greatly appreciated,
Thanks,
Markus



More information about the R-SIG-Finance mailing list