The calculate_lagged() function calculates daily temporal lagged covariates
from the output of calculate_covariates() or calc_*().
Arguments
- from
data.frame(1). A
data.framecontaining calculated covariates returned fromcalculate_covariates()orcalc_*().- date
character(2). Start and end dates of desired lagged covariates. Length of 10 each, format YYYY-MM-DD (ex. September 1, 2023 = "2023-09-01").
- lag
integer(1). Number of lag days.
- locs_id
character(1). Name of unique identifier.
- time_id
character(1). Column containing time values.
- geom
logical(1). Should the function return a
SpatVector? Default isFALSE. The coordinate reference system of theSpatVectoris that offrom.To return as aSpatVector,frommust also be aSpatVector
Note
In order to calculate temporally lagged covariates, from must contain at
least the number of lag days before the desired start date. For example, if
date = c("2024-01-01", "2024-01-31) and lag = 1, from must contain data
starting at 2023-12-31.
If from contains geometry features, calculate_lagged will return a column
with geometry features of the same name.
calculate_lagged() assumes that all columns other than time_id,
locs_id, and fixed columns of "lat" and "lon", follow the genre, variable,
lag, buffer radius format adopted in calc_setcolumns().
Examples
## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
## amount of data which is not included in the package.
if (FALSE) { # \dontrun{
loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
terracliamte_covar <- calculate_terraclimate(
from = terraclimate, # derived from process_terraclimate() example
locs = loc,
locs_id = "id",
radius = 0,
fun = "mean",
geom = FALSE
)
calculate_lagged(
from = terracliamte_covar,
locs_id = "id",
date = c("2023-01-02", "2023-01-10"),
lag = 1,
time_id = "time"
)
} # }