clean_state: Convert Australian state names and abbreviations into a...

Description Usage Arguments Details Value Examples

View source: R/strayr.R

Description

Convert Australian state names and abbreviations into a consistent format

Usage

1
2
3
4
5
6
7
8
9
clean_state(
  x,
  to = "state_abbr",
  fuzzy_match = TRUE,
  max_dist = 0.4,
  method = "jw"
)

strayr(...)

Arguments

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", and "code".

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'

Details

'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'.

Value

a character vector of state names, abbreviations, or codes.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(strayr)

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))

MattCowgill/strayr documentation built on May 31, 2021, 12:15 a.m.