View source: R/state_replace.R
state_replace | R Documentation |
A wrapper function for cat_replace()
that only requires an inputted
vector of messy US state names. state_replace()
uses the built-in character
vector state.name
as the reference clean vector.
state_replace(messy_states, threshold = NA, p = 0)
messy_states |
Vector containing the messy state names that will be replaced
by the closest match from |
threshold |
The maximum distance that will form a match. If this argument is specified, any element in the messy vector that has no match closer than the threshold distance will be replaced with NA. Default: NA |
p |
Only used with method "jw", the Jaro-Winkler penatly size. Default: 0 |
State names are often misspelled or abbreviated in datasets, especially datasets that have been
manually digitized or created. state_replace()
is a warpper function of cat_replace()
that quickly solves
this common issue of mispellings or different formats of state names across datasets. This wrapper
function uses a built in clean list of country names state.name
as the reference clean vector and
replaces your inputted messy vector of names to their nearest match in state.name
.
state_replace()
returns a cleaned version of the bad vector, with each
element replaced by the most similar element of the good vector.
if(interactive()){ #EXAMPLE1 lst <- c("Indianaa", "Wisvconsin", "aLaska", "NewJersey", "Claifoarni") fixed <- state_replace(lst) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.