calc_climatology: Calculate across-year summaries

View source: R/Functions_AcrossYears.R

calc_climatologyR Documentation

Calculate across-year summaries

Description

Calculate across-year summaries

Usage

calc_climatology(X, INDEX, FUN, ...)

Arguments

X

A numeric vector, matrix or data.frame. Rows represent time steps.

INDEX

A numeric vector. Time steps of X.

FUN

A function or a name of a function. The function must accept ... and returns a named or unnamed vector.

...

Additional parameters passed to FUN such as na.rm.

Value

A numeric data.frame where rows represent unique values of INDEX and columns represent combinations of columns of x and FUN output. Columns names contain combinations of names of x and FUN if available.

Notes

The package rSW2metrics offers two pathways to across-year summaries:

  1. aggs_across_years() calculates across-year summaries from output of a time-series metric; this can be calculated after extractions or requested with command-line options -add_aggs_across_yrs and -ts.

  2. Metrics that directly return across-year summaries, i.e., climatologies; those are internally calculated by calc_climatology().

Both pathways utilize the user-defined function fun_aggs_across_yrs() from "Project_Parameters.R.

Examples

calc_climatology(
  1:100,
  INDEX = rep(1:10, each = 10),
  FUN = function(x, ...) {
    tmp <- unname(quantile(x, probs = c(0.05, 0.5, 0.95), ...))
    c(low = tmp[[1]], med = tmp[[2]], high = tmp[[3]])
  },
  type = 1
)


DrylandEcology/rSW2metrics documentation built on May 25, 2023, 10:38 a.m.