This function standardizes country names and adds a new column to the database containing two-letter country codes (ISO 3166-1 alpha-2).

bdc_country_standardized(data, country = "country")

Arguments

data

data.frame. Containing country names

country

character string. The column name with the country assignment of each record. Default = "country".

Value

A data.frame containing two columns: country_suggested (standardized country names) and country_code (two-letter country codes; more details in World Countries, International Organization for Standardization).

Details

Country names are standardized using an exact matching against a list of country names in several languages from International Organization for Standardization. If any unmatched names remain, a fuzzy matching algorithm is used to find potential candidates for each misspelled countries names.

Examples

if (FALSE) {
country <- c("BOLIVIA", "bolivia", "Brasil", "Brazil", "BREZIL")
x <- data.frame(country)

bdc_country_standardized(
  data = x,
  country = "country"
)
}