annual_longest_spell: Annual Longest Spell

View source: R/annual_longest_spell.R

annual_longest_spellR Documentation

Annual Longest Spell

Description

Calculates the length of the longest period each year for which the spell condition is valid

Usage

annual_longest_spell(
  data,
  element,
  station = NULL,
  date = NULL,
  year = NULL,
  spell_type = c("between", "lte", "gte", "excluding between"),
  lower = 0,
  upper = 0.85,
  doy = NULL,
  doy_first = 1,
  doy_last = 366,
  result_name = "max_spell",
  na.rm = FALSE
)

Arguments

data

The data.frame to calculate from

element

The name of the column in data to apply the spell condition to

station

The name of the station column in data, if the data are for multiple station. Spells are calculated separately for each station.

date

The name of the date column in data. This is only needed if year is not specified as it will be created from date.

year

The name of the year column in data. If NULL it will be created using lubridate::year(data[[date]]).

spell_type

The spell condition type. One of "between", "lte" (less than or equal to), "gte" (greater than or equal to) or "outside". See details for explanation.

lower

The lower value of the spell condition (does not apply to spell type = "gte").

upper

The lower value of the spell condition (does not apply to spell type = "lte").

doy

The name of the day of the year (1-366) column in data if filtering to a part of the year. Note that this filter is applied after calculating spell lengths, hence the longest spell could have started outside of this filter. To exclude a part of the year from the calculations completely, filter the data before using annual_longest_spell. If doy is NULL then it can be calculated as yday_366(data[[date]]) if date is provided.

doy_first

The first day of the year to consider the longest spell within.

doy_last

The last day of the year to consider the longest spell within.

result_name

The name of column of the length of the longest spell period in the resulting summary dataset.

na.rm

A logical value. Should NA values be removed from the spell lengths before calculating the longest spell length? Note that NA values in the element column are never removed to prevent spell runs continuing over non consecutive rows.

Value

A summary data.frame of the annual longest spell (for each station).


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