apply.seasonal {lfstat} | R Documentation |
Apply an aggregation function seasonally.
Description
Similar to the functions apply.daily
, apply.monthly
, apply.yearly
etc. from the xts package.
Usage
apply.seasonal(x, varying, fun = function(x) min(x, na.rm = TRUE),
aggregate = NULL, replace.inf = TRUE, origin = 1)
Arguments
x |
an object of class |
varying |
a character vector of length one of a possibly named vector of class |
fun |
the function used for aggregating all elements of a season. |
aggregate |
possibly a function used for aggregating per season. |
replace.inf |
should non-finite values introduced by |
origin |
The start of the hydrological year. If set to 1 (the default) aggregation is carried out using the calendar year. |
Value
a matrix with every (hydrological) year being a row and every column being a season.
Examples
data(ngaruroro)
ng <- as.xts(ngaruroro)
year <- water_year(time(ng), origin = "Sept")
ng10 <- ng[year %in% 1991:2000, ]
# computes the annual minima (AM)
apply.seasonal(ng10, varying = "yearly", origin = 9)
# computes the mean annual minima (MAM)
apply.seasonal(ng10, varying = "yearly", aggregate = mean, origin = 9)
# computes monthly minima (AM)
apply.seasonal(ng10, varying = "monthly", origin = 9)
# computes minima for summer and winter separately
# winter starts in September
seasons <- as.Date(c("1999-09-01", "1999-11-04"))
names(seasons) <- c("winter", "summer")
apply.seasonal(ng10$discharge, varying = seasons, origin = 9)