Skip to contents

These functions summarize only values that satisfy a threshold condition. sum_*() returns zero when valid observations exist but none satisfy the condition. mean_*() returns NA_real_ when no value satisfies the condition.

Usage

sum_above(threshold, na.rm = TRUE)

sum_at_or_above(threshold, na.rm = TRUE)

sum_below(threshold, na.rm = TRUE)

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

mean_above(threshold, na.rm = TRUE)

mean_at_or_above(threshold, na.rm = TRUE)

mean_below(threshold, na.rm = TRUE)

mean_between(lower, upper, inclusive = TRUE, 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

sum_above(0)(c(0, 1.2, 3.4, NA))
#> [1] 4.6
mean_between(18, 26)(c(14, 20, 22, 30))
#> [1] 21