R/calc_extreme_temp_anom.R

Defines functions calc_extreme_temp_anom

Documented in calc_extreme_temp_anom

#' calc_extreme_temp_anom
#'
#'computes max and min anomalies and what year these anomalies occured for temperature
#'
#' @param temp
#'
#' @return max and min anomalies and the years they occurred in
#' @export
#'
#' @examples
calc_extreme_temp_anom = function(temp) {

  # find the max temperature anomaly
  max_anom_temp = max(temp$Anomaly)

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

  # find the min temp anomaly
  min_anom_temp = min(temp$Anomaly)

  # find the min temperature anomaly year that it was found
  min_anom_temp_year = temp %>%
    dplyr::filter("Anomaly" == min_anom_temp) %>%
    dplyr::select(Date) %>%
    as.numeric()


  return(list(max_year = max_anom_temp_year,
              max_temp_anomaly = max_anom_temp,
              min_year = min_anom_temp_year,
              min_temp_anomaly = min_anom_temp))
}
annaclairemarley/HW5262 documentation built on April 5, 2020, 8:59 p.m.