[R] aggregation of a zoo object

jessica.gervais at tudor.lu jessica.gervais at tudor.lu
Tue May 29 21:41:39 CEST 2007


Dear all,

I am trying to execute the following example:

time<-c("2000-10-03 14:00:00","2000-10-03 14:10:00","2000-10-03
14:20:00","2000-10-03 15:30:00","2000-10-03 16:40:00","2000-10-03
16:50:00","2000-10-03 17:00:00","2000-10-03 17:10:00","2000-10-03
17:20:00","2000-10-03 18:30:00","2000-10-04 14:00:00","2000-10-04
14:10:00","2000-10-04 14:20:00","2000-10-04 15:30:00","2000-10-04
16:40:00","2000-10-04 16:50:00","2000-10-04 17:00:00","2000-10-04
18:30:00","2000-10-04 18:30:00","2000-10-04 18:30:00")
# remark the last date is occuring 3 times

precipitation<-c(NA,0.1,0,0,NA,0,0.2,0.3,0.5,6,7,8,9,1,0,0,NA,0,1,0)

library(zoo)

z <- zoo(precipitation, as.POSIXct(time, tz = "GMT"))
Warning message:
some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique in: zoo(precipitation, as.POSIXct(time, tz =
"GMT"))

# then I want to do the sum per hour

z_sum_per_hour <- aggregate(na.omit(z), function(x) as.POSIXct(trunc(x,
"hour")),sum)
Warning message:
some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique in: zoo(rval[i], x.index[i])



Do anyone has an idea how to avoid that ?



Thanks in advance


Jessica



More information about the R-help mailing list