Aggregate covariates
Description
Aggregates a data frame containing a covariate of interest in space and/or time.
aggregate_cov(
data,
var,
time,
unit = NULL,
aggregate_space = NULL,
aggregate_time = NULL,
aggregate_space_fun = "mean",
aggregate_time_fun = "mean",
area = NULL
)Arguments
data: Data frame containing equally spaced (daily, weekly, monthly) incident cases for one or multiple areas.var: Name of the variable that identifies the covariate.time: Name of the variable that identifies the temporal dimension. The values must be in date format (“yyyy-mm-dd”). representing the date of observation for daily data, the first day of the week for weekly, or the first day of the month for monthly observations.unit: Optional name of the variable that identifies the different units for which a time series is available, typically a spatial unit.aggregate_space: Name of variable used to define spatial aggregation groups that contain the different units.aggregate_time: Temporal scale used to perform temporal aggregation. Options are: “week” (ISO 8601), “month”, “year”. See details.aggregate_space_fun: Character indicating the function to be used in the aggregation over space, default is “mean”.aggregate_time_fun: Character indicating the function to be used in the aggregation over time, default is “mean”.area: Deprecated, useunitinstead.
Details
The temporal aggregation requires a number of time points depending on the time scale, e.g. from days to weeks it will require 7 points. Otherwise, it will return NA.
Returns
A data frame with the aggregated covariate.
Examples
# Load data
data("dengue_SP")
# Weekly to monthly total precipitation
aggregate_cov(
dengue_SP,
var = "precip_tot",
time = "date",
aggregate_time = "month",
aggregate_time_fun = "sum"
)