climatic_summary: Calculate summaries from climatic data

View source: R/climatic_summary.R

climatic_summaryR Documentation

Calculate summaries from climatic data

Description

climatic_summary returns a data table displaying summary statistics for element(s) (and for each station) in a given time period.

Usage

climatic_summary(
  data,
  date_time,
  station = NULL,
  elements = NULL,
  year = NULL,
  month = NULL,
  dekad = NULL,
  pentad = NULL,
  to = c("hourly", "daily", "pentad", "dekadal", "monthly", "annual-within-year",
    "annual", "longterm-monthly", "longterm-within-year", "station", "overall"),
  by = NULL,
  doy = NULL,
  doy_first = 1,
  doy_last = 366,
  summaries = c(n = "~dplyr::n()"),
  na_rm = FALSE,
  na_prop = NULL,
  na_n = NULL,
  na_consec = NULL,
  na_n_non = NULL,
  first_date = FALSE,
  n_dates = FALSE,
  last_date = FALSE,
  summaries_params = list(),
  names = "{.fn}_{.col}"
)

Arguments

data

data.frame The data.frame to calculate from.

date_time

Date The name of the date column in data.

station

character(1) The name of the station column in data, if the data are for multiple station.

elements

character The name of the elements column in data to apply the function to.

year

character(1) The name of the year column in data.

month

character(1) The name of the month column in data.

dekad

character(1) The name of the dekad column in data.

pentad

character(1) The name of the pentad column in data.

to

character(1) The date-time format to put the data into.

by

character The name of columns in data to group the summary data by.

doy

character(1) The name of the day of the year (1-366) column in data. If NULL it will be created using lubridate::year(data[[doy]]).

doy_first

integer(1) The first day of the year.

doy_last

integer(1) The last day of the year.

summaries

character A named character vector of summary functions. The names are used as the column names in the results. The values can be any function name as a string or a function call as a formula. e.g. c(mean = "mean", st_dv = "sd", n = "~dplyr::n()")

na_rm

logical(1) If TRUE all na_ parameters are ignored and missing values are removed. If FALSE missing values are not removed unless any na_ parameters are specified.

na_prop

integer(1) Max proportion of missing values allowed

na_n

integer(1) Max number of missing values allowed

na_consec

integer(1) Max number of consecutive missing values allowed

na_n_non

integer(1) Min number of non-missing values required

first_date

logical(1) If TRUE the first instance of date_time when the value equals the summary value is included. Generally only used for extreme summaries i.e. first date_time when the maximum occurred.

n_dates

logical(1) If TRUE the number of date_time points when the value equals the summary value is included. Generally only used for extreme summaries i.e. number of days in which the minimum occurred.

last_date

logical(1) If TRUE the last instance of date_time when the value equals the summary value is included. Generally only used for extreme summaries i.e. last date_time when the maximum occurred.

summaries_params

list Additional parameters to pass to summaries. Must be a list of lists with the same names as summaries.

names

Format of column names. Passed to .names in dplyr::across

Value

A summary data frame for selected element(s) in climatic data.

Examples

# Calculate frequencies for tmin/tmax for each year, month, and station.
# filter daily_niger data for the example
daily_niger_1 <- daily_niger %>% dplyr::filter(year > 1960)
climatic_summary(data = daily_niger_1, date_time = "date", station = "station_name",
                 elements = c("tmin", "tmax"), to = "monthly")

IDEMSInternational/cdms.products documentation built on July 7, 2023, 10:13 a.m.