R/snow_v_rain.R

Defines functions snow_v_rain

Documented in snow_v_rain

#'Volume of snow vs rain (inches)
#'
#'Takes precipitation (inches) and corresponding temperature (F) data and calculates the volume of precipitation that fell as rain vs snow
#'
#'@param climate data frame including columns for precipitation (inches) and temperature (F) observations
#'@return precip_summary a table with volume of precipitation that fell as rain vs snow and average temperature when precipitation fell as rain vs snow.


snow_v_rain = function(climate){
  library(tidyverse)
  precip_summary = climate %>%
    mutate(precip_type = case_when(temp > 32 ~ "Rain",
                                   temp < 32 ~ "Snow")) %>%
             group_by(precip_type) %>%
             summarise(volume = sum(precip),
                       avg_temp = mean(temp))
      return(precip_summary)
}
jjagdeo/climateimpacts documentation built on March 20, 2020, 9:48 p.m.