Skip to content
Prev 106253 / 398506 Next

Hourly Time Series

Using zoo would allow you to retain the date/time portion.  In ts you would
have to represent them as numbers; however, as you can easily switch
from zoo to ts you probably want to use zoo in the first instance:

library(zoo)
library(chron)
Lines <- "DateID        HourID        Metrics
20060920    0                1
20060920    1                2"
z <- read.zoo(textConnection(Lines), header = TRUE, format = "%Y%m%d")
metrics <- aggregate(z[,2], chron(unclass(time(z))) + unclass(z[,1])/24, sum)
metrics
as.ts(metrics)
On 12/11/06, Harshal D Dedhia <harshal at yahoo-inc.com> wrote: