R/recode.R

Defines functions std_short_party

Documented in std_short_party

#' Standardize party codes to single capital letters
#'
#' @param x A vector of characters with unstandardized party, e.g. "Republican", "Not sure"..
#'
#' @return A vector of "D", "R",
#'
#' @importFrom dplyr recode
#'
#' @examples
#' std_short_party(
#'  c("Republican",
#'    "Democrat",
#'    "Not sure",
#'    "Other Party / Independent",
#'    "Never Heard of Person")
#'    )
#'
#'
#' @export
#'
std_short_party <- function(x) {
  dplyr::recode(x,
         Democrat = "D",
         Republican = "R",
         Independent = "I",
         `Never Heard of Person` = "NeverHeard",
         `Not sure` = "NotSure",
         `Not Sure` = "NotSure",
         `Don't know` = "NotSure",
         `Other Party / Independent` = "OtherI",
         `Other Party/Independent` = "OtherI",
         `Skipped` = "",
         `skipped` = "",
         `Not Asked` = ""
  )
}
kuriwaki/rcces documentation built on Sept. 12, 2023, 5:31 p.m.