
Convert Country Names to ISO3 or ISO2 Country Codes
Source:R/convert_country_to_iso.R
convert_country_to_iso.RdThis function converts country names to their corresponding ISO3 or ISO2 country codes. The function uses the countrycode package, which allows for multiple spellings and variations of country names.
Details
The function converts country names to ISO3 or ISO2 codes using the countrycode package. It handles various common and alternative spellings of country names.
Examples
# Convert a single country name to ISO3
convert_country_to_iso("United States")
#> [1] "USA"
# Convert a vector of country names to ISO2
convert_country_to_iso(c("United States", "UK", "Democratic Republic of Congo"), iso3 = FALSE)
#> [1] "US" "GB" "CD"