. :
aggregate(. ~ cut(time, 'hours'), data, mean)
If you only need a quick chart, ggplot2 is your friend:
qplot(cut(time, "hours"), count, data=data, stat='summary', fun.y='mean')
Unfortunately, since cut returns a coefficient, the x axis will not work properly. You might want to write your own, less inconvenient bucketing function for time, for example.
timebucket = function(x, bucketsize = 1,
units = c("secs", "mins", "hours", "days", "weeks")) {
secs = as.numeric(as.difftime(bucketsize, units=units[1]), units="secs")
structure(floor(as.numeric(x) / secs) * secs, class=c('POSIXt','POSIXct'))
}
qplot(timebucket(time, units="hours"), ...)
source
share