vary_threshold: Create varying thresholds

Description Usage Arguments Value Examples

Description

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

Usage

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)

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
Warning message:
1.3% of the discharges (14 observations) are NA values. NAs always terminate a drought event. 

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