Learn R Programming

tidyextreme (version 1.0.0)

calculate_TXx: Calculate monthly maximum value of daily maximum temperature (TXx)

Description

Calculates the highest daily maximum temperature for each month, following ETCCDI definition TXx.

Usage

calculate_TXx(
  df,
  frequency = "daily",
  time_col = NULL,
  tmax_col = NULL,
  temp_col = NULL,
  min_days = 20
)

Value

A tibble with columns: year, month, TXx

Arguments

df

Data frame with climate data

frequency

Temporal frequency: "daily" or "hourly"

time_col

Name of the time column. For daily frequency, the column should be of class Date or a string in the format YYYY-MM-DD. For hourly frequency, the column should be of class POSIXct or a string in the format YYYY-MM-DD HH:MM:SS.

tmax_col

Name of maximum temperature column (daily data)

temp_col

Name of temperature column (for single temp or hourly)

min_days

Minimum days per month for valid calculation (default: 20)

Examples

Run this code
# Daily data with maximum temperature
daily_data <- data.frame(
  date = seq(as.Date("2000-01-01"), as.Date("2002-12-31"), by = "day"),
  tmax = rnorm(1096, mean = 25, sd = 6)
)

calculate_TXx(
  df = daily_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax"
)

# With custom minimum days per month
calculate_TXx(
  df = daily_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax",
  min_days = 25
)

Run the code above in your browser using DataLab