names_to_code: Get country codes from names.

Description Usage Arguments Details Value

View source: R/names.R

Description

names_to_codes() takes in a vector of country names and returns a vector of specified country codes.

Usage

1
2
3
4
5
6
7
8
9
names_to_code(
  names,
  type = "iso3",
  language = c("en", "es", "ru", "ar", "zh", "fr"),
  ignore_case = T,
  fuzzy_matching = "yes",
  method = "jw",
  p = 0.1
)

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.

Value

A vector of country codes matched to the names.


caldwellst/whotilities documentation built on April 8, 2021, 3:52 a.m.