Apply Function Column-wise
Applies an arbitrary function to selected columns of a DTSg
object.
## S3 method for class 'DTSg'
colapply(
  x,
  fun,
  ...,
  cols = self$cols(class = "numeric")[1L],
  resultCols = NULL,
  suffix = NULL,
  helpers = TRUE,
  funby = NULL,
  ignoreDST = FALSE,
  multiplier = 1L,
  funbyHelpers = NULL,
  clone = getOption("DTSgClone")
)x | 
 A   | 
fun | 
 A   | 
... | 
 Further arguments passed on to   | 
cols | 
 A character vector specifying the columns to apply   | 
resultCols | 
 An optional character vector of the same length as
  | 
suffix | 
 An optional character string. The return values of   | 
helpers | 
 A logical specifying if helper data shall be handed over to
  | 
funby | 
 One of the temporal aggregation level functions described in
  | 
ignoreDST | 
 A logical specifying if day saving time is ignored during
formation of the temporal level. See   | 
multiplier | 
 A positive integerish value “multiplying” the
temporal aggregation level of certain   | 
funbyHelpers | 
 An optional   | 
clone | 
 A logical specifying if the object is modified in place or if a clone (copy) is made beforehand.  | 
In addition to the ... argument, this method optionally hands over a
list argument with helper data called .helpers to
fun. .helpers contains the following named elements:
.dateTime: A POSIXct vector containing the
.dateTime column.
periodicity: Same as periodicity field. See
DTSg for further information.
minLag: A difftime object containing the
minimum time difference between two subsequent timestamps.
maxLag: A difftime object containing the
maximum time difference between two subsequent timestamps.
Returns a DTSg object.
# 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 = cumsum, helpers = FALSE, funby = byYm____)
## S3 method
colapply(x = x, fun = cumsum, helpers = FALSE, 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"]
  )
}Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.