Skip to content
Prev 116468 / 398498 Next

Sum per hour

We could do it using either POSIXct or chron:

library(zoo)

# POSIXct
z <- zoo(precipitation, as.POSIXct(time, tz = "GMT"))
aggregate(z, function(x) as.POSIXct(trunc(x, "hour")), sum)

# chron
library(chron)
z <- zoo(precipitation, as.chron(as.POSIXct(time, tz = "GMT"))
aggregate(z, function(x) chron(trunc(times(x), "01:00:00")), sum)
On 5/24/07, jessica.gervais at tudor.lu <jessica.gervais at tudor.lu> wrote: