vincentarelbundock / countrycode

R package: Convert country names and country codes. Assigns region descriptors.
https://vincentarelbundock.github.io/countrycode
GNU General Public License v3.0
342 stars 83 forks source link

Set iso3 for Kosovo to XKX #305

Closed jrspringman closed 2 years ago

jrspringman commented 2 years ago

Is it possible to get the iso3 for Kosovo set to XKX? Not all countries recognize Kosovo's independence, but many datasets treat it as an independent country.

The string Kosovo returns the following warning and yields NA values. Warning messages: 1: Problem while computing iso3 = countrycode::countrycode(country, "country.name", "iso3c"). ℹ Some values were not matched unambiguously: Kosovo

cjyetman commented 2 years ago

The built-in code sets follow precisely the standards as defined by each code sets' primary maintainer. So for instance, the International Organization for Standardization does not include Kosovo/XKX in its ISO 3166-1 alpha-3 standard, therefore {countrycode} will not include that in its iso3c origin/destination code set.

You can easily add custom codes for specific countries like this...

library(countrycode)
country_names <- c('Greece', 'United Kingdom', 'Kosovo', 'France')
countrycode(country_names, 
            origin = 'country.name', 
            destination = 'iso3c', 
            custom_match = c(`Kosovo` = 'XKX'))
#> [1] "GRC" "GBR" "XKX" "FRA"

also see #61

jrspringman commented 2 years ago

Thanks so much!