Skip to contents

These functions summarize runs of consecutive observations that satisfy a condition. Missing values break sequences when na.rm = TRUE.

Usage

max_consecutive_above(threshold, na.rm = TRUE)

max_consecutive_at_or_above(threshold, na.rm = TRUE)

max_consecutive_below(threshold, na.rm = TRUE)

max_consecutive_at_or_below(threshold, na.rm = TRUE)

max_consecutive_between(lower, upper, inclusive = TRUE, na.rm = TRUE)

spell_count_above(threshold, na.rm = TRUE)

spell_count_at_or_above(threshold, na.rm = TRUE)

spell_count_below(threshold, na.rm = TRUE)

spell_count_between(lower, upper, inclusive = TRUE, na.rm = TRUE)

mean_spell_duration_above(threshold, na.rm = TRUE)

max_spell_duration_above(threshold, na.rm = TRUE)

Arguments

threshold

A single finite numeric threshold.

na.rm

If TRUE, missing values are ignored. For proportion functions, the denominator is the number of non-missing observations.

lower, upper

Single finite numeric limits. lower must be less than or equal to upper.

inclusive

If TRUE, values equal to the boundary are included.

Value

A function that takes a numeric vector and returns one numeric value.

Examples

max_consecutive_above(2)(c(1, 3, 4, 1, 5, 6, 7))
#> [1] 3
spell_count_above(2)(c(1, 3, 4, 1, 5, 6, 7))
#> [1] 2