Applies a temporal aggregation level function to the .dateTime column
of a DTSg object and aggregates its values columnwise
to the function's temporal aggregation level utilising a provided summary
function. Additionally, it sets the object's aggregated field to
TRUE. See DTSg for further information.
# S3 method for DTSg
aggregate(x, funby, fun, ..., cols = self$cols(class =
"numeric"), n = FALSE, ignoreDST = FALSE,
clone = getOption("DTSgClone"))A DTSg object (S3 method only).
One of the temporal aggregation level functions described in
TALFs or a user defined temporal aggregation level function.
See details for further information.
A summary function applied columnwise to all the values of the
same temporal aggregation level, for instance, mean. Its
return value must be of length one.
Further arguments passed on to fun.
A character vector specifying the columns to aggregate.
A logical specifying if a column named .n giving the number of values per temporal aggregation level is added. See details for further information.
A logical specifying if day saving time is ignored during aggregation. See details for further information.
A logical specifying if the object is modified in place or if a clone (copy) is made beforehand.
Returns an aggregated DTSg object.
User defined temporal aggregation level functions have to return a
POSIXct vector of the same length as the time series and
accept two arguments: a POSIXct vector as its first and a
list with helper data as its second. This list
in turn contains the following named elements:
timezone: Same as timezone field. See
DTSg for further information.
ignoreDST: Same as ignoreDST argument.
periodicity: Same as periodicity field. See
DTSg for further information.
Depending on the number of columns to aggregate, the .n column contains different counts:
One column: The counts are calculated from the value column without
any missing values. This means that missing values are always stripped
regardless of the value of a possible na.rm argument.
More than one column: The counts are calculated from the .dateTime column including all missing values.
ignoreDST tells a temporal aggregation level function if it is
supposed to ignore day saving time while forming new timestamps. This can be
a desired feature for time series strictly following the position of the sun
(such as hydrological time series). Doing so ensures that diurnal variations
are preserved under all circumstances and that all intervals are of
“correct” length. This feature requires that the periodicity of the
time series is not unrecognised and is supported by the following temporal
aggregation level functions of the package:
# NOT RUN {
# new DTSg object
x <- DTSg$new(values = flow)
# mean yearly river flows
## R6 method
x$aggregate(funby = byY_____, fun = mean, na.rm = TRUE)
## S3 method
aggregate(x = x, funby = byY_____, fun = mean, na.rm = TRUE)
# }
Run the code above in your browser using DataLab