vary_threshold: Create varying thresholds

View source: R/misc.R

vary_thresholdR Documentation

Create varying thresholds

Description

Helper function to easily create a daily, weekly, monthly or seasonal varying threshold.

Usage

vary_threshold(x, varying = "constant",
               fun = function(x) quantile(x, probs = 0.05, na.rm = TRUE), ...)

Arguments

x

an object which can be coerced to class 'xts'. Either with a single column or with a column named 'discharge'.

varying

if varying is a character vector of length one, values of "constant", "daily", "weekly" and "monthly" are allowed. If a vector of class POSIX is provided, a seasonal varying threshold is computed, where the times provided define the start of the season. Only the day of the year is taken, the year itself doesn't have a meaning.

fun

a function accepting a single argument and returning either a vector of length one or a vector as long as x.

...

additional arguments, passed on to fun

Value

a vector as long as x.

Examples

data(ngaruroro)
ng <- as.xts(ngaruroro)["1983::1985", ]
r <- find_droughts(ng, varying = "monthly")
plot(r)

thr1 <- vary_threshold(ng, varying = "weekly", fun = mean, na.rm = TRUE)
plot(thr1)

thr2 <- vary_threshold(ng, varying = "monthly", fun = mean, na.rm = TRUE)
lines(thr2, col = 2)

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