R/rank_to_pg.R

Defines functions rank_to_pg

Documented in rank_to_pg

###########################################################################################################################################################
#' Rank to Paygrades
#'
#' @param df a dataframe of ranks and possibly services
#' @param service either "Multi", in which case columns "service" and "rank" must be present in df, or one of "Army", "Air Force", "Navy", "Coast Guard", in which case column rank must be present in df 
#'
#' @return This function returns a dataframe with an additional column for paygrade
#'
#' @author Bjorn Kallerud
#'
#' @import dplyr
#'
#' @export

rank_to_pg <- function(df, srvc) {
  
  if (srvc != "Multi") {
    
    df_out <- df %>% 
      left_join(df_rank_pg %>% filter(service == srvc) %>% select(-service), by = c("rank"))
    
  }

  if (srvc == "Multi") {
    
    df_out <- df %>% 
      left_join(df_rank_pg, by = c("service", "rank"))
    
  }
  
  if (nrow(df_out) > nrow(df)) {warning("Match is not unique.")}
  
  return(df_out)

}
                                      
                                      
                                      
bjornkallerud/dataOPS documentation built on Oct. 1, 2022, 10:42 a.m.