1) ts. Since this is a regular time series, convert it to the ts series, and then combine it from frequency 24 to frequency 1:
> aggregate(ts(x2[, 2], freq = 24), 1, mean)
giving:
Time Series: Start = 1 End = 4 Frequency = 1 [1] 108.5 132.5 156.5 180.5
2) the zoo. It uses a zoo. The zoo package can also handle irregularly spaced rows (if we need to expand it). Below day.hour is the day number (1, 2, 3, 4) plus an hour as part of the day, so floor(day.hour) is just the day number:
> library(zoo) > day.hour <- seq(1, length = length(x2[, 2]), by = 1/24) > z <- zoo(x2[, 2], day.hour) > aggregate(z, floor, mean) 1 2 3 4 108.5 132.5 156.5 180.5
If zz is the result, then coredata(zz) and time(zz) are values ββand times, respectively, like regular vectors.
G. grothendieck
source share