Skip to contents

These functions create summary functions for use inside the statistics argument of summarise_weather_window(), scan_windows(), and window_pane(). Each function returns a closure that is applied to a numeric vector from one weather variable.

Usage

count_above(threshold, na.rm = TRUE)

count_at_or_above(threshold, na.rm = TRUE)

count_below(threshold, na.rm = TRUE)

count_at_or_below(threshold, na.rm = TRUE)

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

proportion_above(threshold, na.rm = TRUE)

proportion_at_or_above(threshold, na.rm = TRUE)

proportion_below(threshold, na.rm = TRUE)

proportion_at_or_below(threshold, na.rm = TRUE)

proportion_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

count_above(30)(c(28, 31, 33, NA))
#> [1] 2
count_between(18, 26)(c(17, 18, 22, 27))
#> [1] 2
proportion_at_or_above(90)(c(88, 91, 95, NA))
#> [1] 0.6666667

statistics <- list(
  temp = list(hours_18_26 = count_between(18, 26)),
  rh = list(prop_humid = proportion_at_or_above(90))
)