# NOT RUN {
# new DTSg object
x <- DTSg$new(values = flow)
# linear interpolation of missing values
## R6 method
x$colapply(fun = interpolateLinear)
## S3 method
colapply(x = x, fun = interpolateLinear)
# daily cumulative sums per month
## R6 method
x$colapply(fun = function(x, ...) {cumsum(x)}, funby = byYm____)
## S3 method
colapply(x = x, fun = function(x, ...) {cumsum(x)}, funby = byYm____)
# calculate moving averages with the help of 'runner' (all four given
# approaches provide the same result with explicitly missing timestamps)
if (requireNamespace("runner", quietly = TRUE) &&
packageVersion("runner") >= numeric_version("0.3.5")) {
wrapper <- function(..., .helpers) {
runner::runner(..., idx = .helpers[[".dateTime"]])
}
## R6 method
x$colapply(fun = runner::runner, f = mean, k = 5 , lag = -2 )
x$colapply(fun = wrapper , f = mean, k = "5 days", lag = "-2 days")
x$colapply(
fun = runner::runner,
f = mean,
k = "5 days",
lag = "-2 days",
idx = x$getCol(col = ".dateTime")
)
x$colapply(
fun = runner::runner,
f = mean,
k = "5 days",
lag = "-2 days",
idx = x[".dateTime"]
)
## S3 method
colapply(x = x, fun = runner::runner, f = mean, k = 5 , lag = -2 )
colapply(x = x, fun = wrapper , f = mean, k = "5 days", lag = "-2 days")
colapply(
x = x,
fun = runner::runner,
f = mean,
k = "5 days",
lag = "-2 days",
idx = getCol(x = x, col = ".dateTime")
)
colapply(
x = x,
fun = runner::runner,
f = mean,
k = "5 days",
lag = "-2 days",
idx = x[".dateTime"]
)
}
# }
Run the code above in your browser using DataLab