View source: R/clean country names.R
gta_clean_country_names | R Documentation |
gta_clean_country_names()
takes a vector of country names
as an input and converts them to the country names used in the GTA database.
gta_clean_country_names(
country,
conversionTable = FALSE,
customConversion = NULL
)
country |
a vector of country names |
conversionTable |
set to TRUE if the function should return a conversion table which shows how each unique value in 'country' is converted by the function |
customConversion |
If you wish to overwrite the default function behavior you can add a named vector to the function which contains as names the name of the the country name to be converted and as value the name function should convert to. Eg: Your data contains South - and North Korea which you do not wnat to convert according to the GTA nomenclature: –> c("South Korea" = "Korea (S)", "North Korea" = "Korea, (N)") |
If a country cannot or cannot uniquely be matched to one country in the gta nomenclature, NA is returned. If you want a table with unique country names from the input vector, the name they were converted to and information on whether the function changed the name, set conversionTable to true. This will output a tibble with these three columns.
The function uses gtalibrary::country_regex which contains a regex for each country which inputs are matched against.
a_mess <- tibble::tible(
country = c(
"Korea, the one in the north",
"Korea, this time in the south",
"Burma",
"Germany (EU Country)",
"Bosnia",
"USA"
)
# a_mess %>%
mutate(clean_names = gta_clean_country_names(country))
# if you wish to convert the value "Korea, this time in the south" to "South Korea" and leave "USA" unchanged,
supply a named vector to customConversion.
# function value:
custom <- ("Korea, this time in the south" = "South Korea", "USA" = "USA")
a_mess %>%
mutate(clean_names = gta_clean_country_names(country, customConversion = custom))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.