names_to_codes()
takes in a vector of country names and returns a vector of
specified country codes.
Arguments
- names
A character vector of country names.
- type
A character value specifying the type of country code to return. Defaults to ISO3. All possible values available through
country_code_types()
.- language
A character value specifying the language of the country names. Should be specified using the ISO2 language code. Defaults to "en", but matching available for all 6 official WHO languages. Possible values are "en", "es", "ar", "fr", "ru", and "zh".
- ignore_case
A logical value specifying whether or not to ignore case when string matching. Defaults to TRUE.
- fuzzy_matching
A character value specifying whether or not to do fuzzy matching, or to require user input when no exact match is found. Defaults to "yes".
- method
A character value specifying the distance method for use in fuzzy matching if an exact match is not found. Defaults to Jaro-Winker due to its value in matching names. See
stringdist::stringdist()
for all possible methods.- p
A numeric value between 0 and 0.25 specifying the penalty factor for Jaro-Winkler distance. Ignored if method is not "jw".
Details
The function first searches for exact matches in the countries
data frame, and if none are found, uses fuzzy matching to guess the country.
Matching is done using stringdist
fuzzy matching methods,
although names_to_codes()
allows the user to not do any fuzzy matching (non-exact
matches returned as NA
) or require user input.