normal_state {campfin}R Documentation

Normalize US State Abbreviations

Description

Return consistent version of a state abbreviations using ⁠stringr::str_*()⁠ functions. Letters are capitalized, all non-letters characters are removed, and excess whitespace is trimmed and squished, and then abbrev_full() is called with usps_state.

Usage

normal_state(
  state,
  abbreviate = TRUE,
  na = c("", "NA"),
  na_rep = FALSE,
  valid = NULL
)

Arguments

state

A vector of US state names or abbreviations.

abbreviate

If TRUE (default), replace state names with the 2-digit abbreviation using the built-in state.abb and state.name vectors.

na

A vector of values to make NA.

na_rep

logical; If TRUE, make all single digit repeating strings NA (removes valid "AA" code for "American Armed Forces").

valid

A vector of valid abbreviations to compare to and remove those not shared.

Value

A vector of normalized 2-digit state abbreviations.

See Also

Other geographic normalization functions: abbrev_full(), abbrev_state(), check_city(), expand_abbrev(), expand_state(), fetch_city(), normal_address(), normal_city(), normal_zip(), str_normal()

Examples

normal_state(
  state = c("VT", "N/A", "Vermont", "XX", "ZA"),
  abbreviate = TRUE,
  na = c("", "NA"),
  na_rep = TRUE,
  valid = NULL
)

[Package campfin version 1.0.11 Index]