-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virgin islands (USA) country code missing (VIR) #333
Comments
Which version are you using? library(countrycode)
packageVersion("countrycode")
#> [1] '1.5.0'
countrycode::countrycode("VIR", "iso3c", "country.name")
#> [1] "U.S. Virgin Islands" |
Same version 1.5.0 |
"Virgin Islands (USA)" is a particularly hard string to match without causing a problem with matching "USA" to "USA". These are the variations of names for Virgin Islands that will work and are tested: countrycode/tests/testthat/data-known-name-variations.R Lines 167 to 179 in 7164698
for example... library(countrycode)
packageVersion("countrycode")
#> [1] '1.5.0'
country_names <-
c(
"U.S. Virgin Islands",
"United States Virgin Islands",
"US Virgin Islands",
"U.S. Virgin Islands",
"Virgin Islands, US",
"Virgin Islands, U.S.",
"Virgin Islands, (U.S.)",
"Virgin Islands, (US)",
"Virgin Islands US",
"Virgin Islands U.S.",
"Virgin Islands (U.S.)",
"Virgin Islands (US)"
)
countrycode(country_names, origin = "country.name", destination = "iso3c")
#> [1] "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" "VIR" One way around this if you have "Virgin Islands (USA)" in your source data is to use the library(countrycode)
countrycode(
sourcevar = "Virgin Islands (USA)",
origin = "country.name",
destination = "iso3c",
custom_match = c("Virgin Islands (USA)" = "VIR")
)
#> Warning: Some strings were matched more than once, and therefore set to <NA> in the result: Virgin Islands (USA),VIR,USA
#> [1] "VIR" Otherwise, you could modify your source data first, with something like... library(dplyr)
library(countrycode)
source_data <- data.frame(country = c("Virgin Islands (USA)", "Canada", "United States"))
source_data %>%
mutate(country = case_when(
country == "Virgin Islands (USA)" ~ "U.S. Virgin Islands",
.default = country
)) %>%
mutate(iso3c = countrycode(country, "country.name", "iso3c"))
#> country iso3c
#> 1 U.S. Virgin Islands VIR
#> 2 Canada CAN
#> 3 United States USA |
No description provided.
The text was updated successfully, but these errors were encountered: