Skip to contents

These functions create summaries from expressions evaluated in a weather window data frame. They are used inside the special .conditions entry of statistics.

Usage

count_when(condition, na.rm = TRUE)

proportion_when(condition, na.rm = TRUE)

sum_when(variable, condition, na.rm = TRUE)

mean_when(variable, condition, na.rm = TRUE)

max_when(variable, condition, na.rm = TRUE)

min_when(variable, condition, na.rm = TRUE)

max_consecutive_when(condition, na.rm = TRUE)

spell_count_when(condition, na.rm = TRUE)

mean_spell_duration_when(condition, na.rm = TRUE)

max_spell_duration_when(condition, na.rm = TRUE)

Arguments

condition

An expression evaluated in the window data frame.

na.rm

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

variable

A numeric column evaluated in the window data frame.

Value

A function marked as a windcut condition summary. It receives a data frame and returns one numeric value.

Examples

weather <- data.frame(temp = c(17, 20, 24), rh = c(88, 92, 95), rain = c(0, 1, 0))
count_when(temp >= 18 & temp <= 26 & rh >= 90)(weather)
#> [1] 2

statistics <- list(
  temp = list(mean = "mean"),
  .conditions = list(
    favorable_hours = count_when(temp >= 18 & temp <= 26 & rh >= 90)
  )
)