clean_state | R Documentation |
Convert Australian state names and abbreviations into a consistent format
clean_state(
x,
to = "state_abbr",
fuzzy_match = TRUE,
max_dist = 0.2,
method = "jw"
)
strayr(...)
x |
a (character) vector containing Australian state names or abbreviations or a (numeric) vector containing state codes (1 = NSW, 2 = Vic, 3 = Qld, 4 = SA, 5 = WA, 6 = Tas, 7 = NT, 8 = ACT). |
to |
what form should the state names be converted to? Options are "state_name", "state_abbr" (the default), "iso", "postal", "code" and "colour". |
fuzzy_match |
logical; either TRUE (the default) which indicates that approximate/fuzzy string matching should be used, or FALSE which indicates that only exact matches should be used. |
max_dist |
numeric, sets the maximum acceptable distance between your string and the matched string. Default is 0.4. Only relevant when fuzzy_match is TRUE. |
method |
the method used for approximate/fuzzy string matching. Default is "jw", the Jaro-Winker distance; see '??stringdist-metrics' for more options. |
... |
all arguments to 'strayr' are passed to 'clean_state' |
'strayr()' is a wrapper around 'clean_state()' and is provided for backwards compatibility. 'strayr()' is soft-deprecated, but will not be removed for the foreseeable future. New code should use 'clean_state()'.
a character vector of state names, abbreviations, or codes.
x <- c("western Straya", "w. A ", "new soth wailes", "SA", "tazz")
# Convert the above to state abbreviations
clean_state(x)
# Convert the elements of `x` to state names
clean_state(x, to = "state_name")
# Disable fuzzy matching; you'll get NAs unless exact matches can be found
clean_state(x, fuzzy_match = FALSE)
# You can use clean_state in a dplyr mutate call
x_df <- data.frame(state = x, stringsAsFactors = FALSE)
## Not run: x_df %>% mutate(state_abbr = clean_state(state))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.