apply.seasonal: Apply an aggregation function seasonally.

Description Usage Arguments Value Examples

Description

Similar to the functions apply.daily, apply.monthly, apply.yearly etc. from the xts package.

Usage

1
2
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 startpoints 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
 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)

Example output

Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: lmom
Loading required package: lattice
      [,1]
1991 3.965
1992 4.570
1993 3.813
1994 3.244
1995 4.462
1996 5.652
1997 3.959
1998 3.375
1999 4.548
2000 3.839
[1] 4.1427
         1      2     3      4     5      6      7      8      9     10     11
1991 3.965  4.234 4.964  4.573 7.274  6.240  7.570 11.467  7.274 15.002  8.240
1992 5.994  4.570 4.728  4.936 4.887  9.412  8.873 14.205  8.584  6.747  7.849
1993 4.742  3.813 5.664  5.659 7.495  8.300  7.193  6.758 12.693 13.790 10.064
1994 3.923  3.844 3.244  3.627 4.745  8.124 10.942 10.120  6.848  6.679  5.573
1995 4.462  5.268 6.060 11.076 8.363 13.230 14.397 11.331  7.950 12.708 12.547
1996 6.723 10.365 7.970 14.181 9.592  7.364 16.091 11.015 11.013  9.535  7.651
1997 5.577  4.410 4.835  5.575 3.959 10.541  8.871  7.632  9.867  8.099  5.882
1998 3.375  3.508 3.648  4.220 4.327  5.801 14.352 13.326 13.568 11.582  5.785
1999 4.644  4.548 4.551  4.600 8.904  9.071  8.529 11.442  9.418  9.654  6.525
2000 5.530  4.402 3.839  4.665 6.955  7.409  9.086 10.556  8.176  6.209  6.608
        12
1991 4.732
1992 4.779
1993 8.932
1994 4.965
1995 6.091
1996 5.652
1997 7.663
1998 4.632
1999 6.022
2000 8.242
     winter summer
1991  7.274  3.965
1992  6.747  4.570
1993 12.693  3.813
1994  6.679  3.244
1995  7.950  4.462
1996  9.535  5.652
1997  7.767  3.959
1998  9.625  3.375
1999  9.418  4.548
2000  6.209  3.839

lfstat documentation built on May 2, 2019, 6:07 p.m.