Learn R Programming

tidyweather (version 0.2.0)

summarise_weather: Summarise Weather Extremes and Key Indicators

Description

This function calculates summary metrics for weather data, including the number of frost days and the last frost day, grouped by one or more grouping variables. The function uses package-wide options for thresholds and year completeness.

Usage

summarise_weather(.data)

Value

A tibble with one row per group, containing the following columns:

number_frost_days

Number of days where minimum temperature is below the frost threshold.

last_frost_day

The day of year of the last frost (or NA if none).

Arguments

.data

A tibble or data frame containing daily weather data. Must include at least a mint column for daily minimum temperatures. A day column is recommended if require_full_year = TRUE.

Details

The function retrieves thresholds and settings from the global tidyweather options via weather_options$get(). The default frost threshold is weather_options$get("extreme.frost_threshold") and require_full_year is weather_options$get("require_full_year"). These can be changed using weather_options$set().

This function is designed to work with grouped tibbles (e.g., after dplyr::group_by()), applying the summary per group.

Examples

Run this code
library(dplyr)

# Example weather data (daily minimum temperatures)
weather_data <- read_weather(system.file("extdata/ppd_72150.met", package = "tidyweather"))

# Summarise without grouping
weather_options$set("require_full_year" = FALSE)
summarise_weather(weather_data)

# Summarise by group (e.g., year)
weather_data_grouped <- weather_data %>% group_by(year)
summarise_weather(weather_data_grouped)

Run the code above in your browser using DataLab