Learn R Programming

tidyextreme (version 1.0.0)

calculate_DTR: Calculate diurnal temperature range (DTR)

Description

Calculates the mean and standard deviation of daily temperature range (difference between maximum and minimum temperature) per year.

Usage

calculate_DTR(
  df,
  frequency = "daily",
  time_col = NULL,
  tmax_col = NULL,
  tmin_col = NULL,
  temp_col = NULL
)

Value

A tibble with columns: year, DTR_mean, DTR_sd, n_days

Arguments

df

Data frame with climate data

frequency

Temporal frequency: "daily" or "hourly" (string)

time_col

Name of the time column (string). 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) (string)

tmin_col

Name of minimum temperature column (daily data) (string)

temp_col

Name of temperature column (hourly data) (string)

Examples

Run this code
# Daily data with maximum and minimum 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 = 5),
  tmin = rnorm(1096, mean = 15, sd = 5)
)

calculate_DTR(
  df = daily_data,
  frequency = "daily",
  time_col = "date",
  tmax_col = "tmax",
  tmin_col = "tmin"
)

Run the code above in your browser using DataLab