r - Aggregating 10 minute data to hourly mean with the hourly.apply function fails -
i have file date/time info , measured values said date , time. values measured every 10 minutes course of study of 1 month, , attempting time series analysis eventually. before however, wanted aggregate 10 min intervals hourly intervals calculating mean measurement of every 60 minutes. here sample of data(a total of 4319 observations):
date/time value 2013-01-01 00:00:00 31,439999 2013-01-01 00:10:00 33,439999 2013-01-01 00:20:00 39 2013-01-01 00:30:00 35,279999 2013-01-01 00:40:00 37,279999 2013-01-01 00:50:00 32,199997 2013-01-01 01:00:00 35,279999 2013-01-01 01:10:00 38,199997
my date/time info of type posixlt , values measured of type factor. have searched on site , have found several topics posted other users not apply me, or can not recreate same results using suggestions given on posts.
for example, user asked exact same question me: aggregate values of 15 min steps values of hourly steps , followed steps answers provided.
library(xts) dat.xts <- xts(data$values, as.posixct(data$datetime)) hourly.apply(dat.xts,mean)
but lastly line next error message:
error: not find function "hourly.apply"
although did install xts bundle zoo package, hourly.apply function appears stem from. reason this? give thanks in advance.
"hourly.apply" doesn't seem exist looking @ 'apply.daily' function in xts bundle seems straightforward create.
see xts::apply.daily. i've changed 'days' 'hours' produce following
apply.hourly <- function(x, fun,...) { ep <- endpoints(x, 'hours') period.apply(x, ep, fun, ...) }
try out
my.time <- seq(from = as.posixct('2000-01-01 00:00:00'), = as.posixct('2000-01-01 2:00:00'), = '10 min') my.data <- rep(10, length = length(my.time)) my.data <- as.xts(my.data, order.by = my.time) apply.hourly(my.data, sum) [,1] 2000-01-01 00:50:00 60 2000-01-01 01:50:00 60 2000-01-01 02:00:00 10
r statistics time-series aggregation xts
No comments:
Post a Comment