Get USA State Name & Abbreviation in R (2 Examples)
In this post, I’ll show how to get a USA state name and abbreviation in the R programming language.
Example 1: Get State Name from State Abbreviation
state.name[grep("CA", state.abb)] # Convert abbreviation to name # [1] "California" |
state.name[grep("CA", state.abb)] # Convert abbreviation to name # [1] "California"
Example 2: Get State Abbreviation from State Name
state.abb[grep("California", state.name)] # Convert name to abbreviation # [1] "CA" |
state.abb[grep("California", state.name)] # Convert name to abbreviation # [1] "CA"