R/calc_extreme_rain_anom.R

Defines functions calc_extreme_rain_anom

Documented in calc_extreme_rain_anom

#' calc_extreme_rain_anom
#'
#'computes max and min anomalies and what year these anomalies occured for precipitation
#'
#' @param rain
#'
#' @return list of max and min anomalies and their years
#' @export
#'
#' @examples

calc_extreme_rain_anom = function(rain) {

  # find the max precipitation anomaly
  max_anom_rain = max(rain$Anomaly)

  # find the max temperature anomaly year that it was found
  max_anom_rain_year = rain %>%
    dplyr::filter("Anomaly" == max_anom_rain) %>%
    dplyr::select(Date) %>%
    as.numeric()

  # find the min precipitation anomaly
  min_anom_rain = min(rain$Anomaly)

  # find the max temperature anomaly year that it was found
  min_anom_rain_year = rain %>%
    dplyr::filter("Anomaly" == min_anom_rain) %>%
    dplyr::select(Date) %>%
    as.numeric()

  return(list(max_year = max_anom_rain_year,
              max_anom = max_anom_rain,
              min_year = min_anom_rain_year,
              min_anom = min_anom_rain))

}
annaclairemarley/HW5262 documentation built on April 5, 2020, 8:59 p.m.