apply.seasonal: Apply an aggregation function seasonally.

View source: R/misc.R

apply.seasonalR 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 'xts' or 'zoo'. The time series which should get aggregated.

varying

a character vector of length one of a possibly named vector of class 'Date' or coercible to 'Date'. Valid character vectors are "daily", "weekly", "monthly" or "constant". If of class 'Date', the elements are considered as start points of a season. See Examples.

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 fun be omitted?

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)

lfstat documentation built on Nov. 10, 2022, 5:42 p.m.