dry_interval: Longest interval of consecutive dry days

Description Usage Arguments Details Value Examples

View source: R/dry_interval.R

Description

Determines the longest interval of consecutive days that are considered "dry". Values of x that are less than rain_cutoff are categorized as dry.

Usage

1
2
3
4
5
6
dry_interval(
  x,
  rain_cutoff = 1,
  period = c("start", "mid", "end"),
  na.rm = TRUE
)

Arguments

x

numeric vector of rainfall measurements

rain_cutoff

minimum amount of rainfall to count as non-dry day

period

period to measure longest dry spell; see value

na.rm

logical indicating treatment of NA values; by default, na.rm = TRUE, NA values are ignored. If set to FALSE, any NA values in x will result in a return value of NA

Details

Missing values are not simply removed for purpose of calculation. If x includes NA values and na.rm = FALSE, NA is returned. However, when x includes NA values and na.rm = TRUE, special consideration is required. In contrast with other methods, NA cannot be dropped without significant implications on calculations. Consider a vector of c(0, 0, NA, 0). If NA values are removed, the vector reduces to c(0, 0, 0) and the longest consectutive stretch of dry days becomes 3. This is not an accurate representation of the data. Instead, when na.rm = TRUE, vectors with NA values will evaluate missing values as non-dry days. In the example above, this results in the longest dry interval being 2. This provides a more accurate representation of dry day intervals based on non-missing data.

Value

numeric vector of length 1 with the number of days that have rainfall less than rain_cutoff; value returned is determined by value of period:

start

number of consecutive days at beginning of season with less than rain_cutoff of measured rain; if first day of season had rainfall greater than or equal to rain_cutoff, the returned value will be zero

mid

longest stretch of days with less than rain_cutoff contained within the period; if rainfall was less than rain_cutoff for every day in defined season, the returned value will be zero

end

number of consecutive days at end of season with less than rain_cutoff of measured rain; if last day of season had rainfall greater than or equal to rain_cutoff, the returned value will be zero

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
  rain <- c(0, 2, 3, 0, 0, 2, 0, 3, 0, 0, 0)
  # Longest interval at the end of season
  dry_test <- wxsumR:::dry_interval(x = rain, period = "end")
  dry_test
  # 3

  # Longest interval in middle of season
  dry_test <- wxsumR:::dry_interval(x = rain, period = "mid")
  dry_test
  # 2

  # Longest interval at start of season, considering days with rain of 2 or
  # lower (unitless) as dry days
  dry_test <- wxsumR:::dry_interval(x = rain, rain_cutoff = 2, period = "start")
  dry_test
  # 2

## End(Not run)

jcoliver/weathercommand documentation built on Sept. 12, 2021, 3:28 a.m.