This is a convenience function to help standardize odd-looking state abbreviations based on a reference list of allowed abbreviations.

recode_state(dat, state_table, oldvar = "state", newvar = "state_new")

Arguments

dat

data frame: input data with a state variable

state_table

data frame: input data holding valid abbreviations

oldvar

character: name of state variable

newvar

character: name of new state variable

See also

Other functions for standardizing state license data: recode_month, state_abbreviations

Examples

data(state_abbreviations) dat <- data.frame(state = c("M0", "mo", "Mo", "MR", "YY")) recode_state(dat, state_abbreviations)
#> state state_new #> 1 M0 MO #> 2 mo MO #> 3 Mo MO #> 4 MR <NA> #> 5 YY <NA>