Aggregate along the time dimension
temporal_aggregate.RdTakes data with a column in a time format (posix or date) and aggregates into
groups defined by breaks while retaining theme and spatial information.
Much of the setup and checks mirrors that of theme_aggregate() and
spatial_aggregate(), and then passes to general_aggregate().
Usage
temporal_aggregate(
dat,
breaks = "all_time",
timecol = "infer",
groupers,
aggCols,
funlist,
geonames = NULL,
prefix = "temporal_",
failmissing = TRUE,
auto_ewr_PU = FALSE,
...
)Arguments
- dat
sf or tibble or dataframe of values to aggregate, with necessary grouping information for non-temporal axes (e.g. scenario, location, theme). Not necessarily the same as
dataingeneral_aggregate()- this function makes necessary adjustments to the data before callinggeneral_aggregate()- breaks
breaks for the time groupings. default 'all_time' collapses over the whole period, otherwise as in
base::cut.POSIXt()(takes the character options there, or time objects)- timecol
name of the column with time in it. Default 'infer' infers which it is by looking for POSIXt or Date types.
- groupers
as in
general_aggregate(), with the note that these should be all grouping columns except any spatial information. Spatial information is automatically added togroupersbefore passing togeneral_aggregate().- aggCols
an expression for the columns to aggregate (the data columns). See
selectcreatorfor formats- funlist
a list of functions and their arguments used to aggregate the data. See
functionlisterfor creation in many cases. The situation with a bare anonymous function, e.g.~mean(., na.rm = T)is not supported because we need a name. Use a named list if using anonymous functions, e.g.list(mean = ~mean(., na.rm = T)). If using functions with a data-variable argument, e.g. weighted.mean with a column of weights, we now (as ofdplyr1.1) have some workarounds. One option is if specified as a function argument, the function can just go in as a bare name or anonymous. If specified elsewhere, it can be wrapped inrlang::quo(), e.g.agglist <- rlang::quo(list(mean = mean, wm = ~weighted.mean(., weight_column_name, na.rm = T))). If it isn't, there is now an internal workaround to add that on that seems to be stable but may cause unforeseen issues. This workaround also allows building custom aggregation functions (not-anonymous) with the data-variable argument either exposed or hardcoded (seeSpatialWeightedMean()). The error checks for names do not work for quosures, so make sure you name the list if usingrlang::quo().- geonames
additional columns of information to persist through the aggregation. Cannot change with the main
groupers. Developed to persist information about polygons through subsequent theme aggregations, but could be more general- prefix
prefix character, differs from
general_aggregate()in that default is'temporal_'instead of'agg_'.- failmissing
logical, default
TRUE: fail if the requested grouping or aggregation columns not exist. IfFALSE, proceed with those that do exist and silently drop those that don't. Similar totidyselect::all_of()vstidyselect::any_of()intidyselect- auto_ewr_PU
logical, default FALSE. If TRUE, automatically infers whether this is an EWR dataset and has not yet been spatially aggregated. If so, applies grouping by 'planning_unit_name' and SWSDLName' since EWRs are defined in those units. The preferred solution is to include it in
groupershere (for on-off), or inmulti_aggregate()to usegroup_until. If none of those solutions happen, though, it aborts to prevent incorrect pooling over rows in different planning units and sdl units.- ...
arguments passed to the aggregation functions. This is very limited, and does not work with data arguments under most conditions. Almost always better to specify explicitly when building
funlist, but works OK with simple functions, e.g. passingna.rm = TRUEto mean