Parse a state name or abbreviation from a string. These data should be at the end of the string (i.e. the last word or two). If a postal code follows the, use pm_postal_parse first to remove those data from pm.address.

pm_state_parse(.data, dictionary, locale = "us")

Arguments

.data

A postmastr object created with pm_prep

dictionary

Optional; a tbl created with pm_dictionary to be used as a master list for states. If none is provided, the states object will be used as the default directory.

locale

A string indicating the country these data represent; the only current option is "us" but this is included to facilitate future expansion.

Value

A tibble with a new character variable pm.state that contains the two-letter abbreviation for the given U.S. state. This follows USPS addressing standards, which require that the state abbreviation be used. If a state name or abbreviation is not detected in the string, a value of NA will be returned. If it does not yet exist, a copy of the address variable will be created in pm.address and returned with state name or abbreviation removed.