country_name {countries} | R Documentation |
Convert and translate country names
Description
This function recognises and converts country names to different nomenclatures and languages using a fuzzy matching algorithm.
country_name()
can identify countries even when they are provided in mixed formats or in different languages. It is robust to small misspellings and recognises many alternative country names and old nomenclatures.
Usage
country_name(
x,
to = "ISO3",
fuzzy_match = TRUE,
verbose = FALSE,
simplify = TRUE,
poor_matches = FALSE,
na_fill = FALSE,
custom_table = NULL
)
Arguments
x |
A vector of country names |
to |
A string containing the desired naming conventions to which |
fuzzy_match |
Logical value indicating whether fuzzy matching of country names should be allowed ( |
verbose |
Logical value indicating whether the function should print to the console a full report. Default is |
simplify |
Logical value. If set to |
poor_matches |
Logical value. If set to |
na_fill |
Logical value. If set to |
custom_table |
Custom conversion table to be used. This needs to be a |
Value
Returns a vector of converted country names. If multiple nomenclatures are passed to the argument to
, the vectors are arranged in a data frame. If simplify=FALSE
, the function will return a list object.
See Also
is_country, match_table, find_countrycol
Examples
#Convert country names to a single nomenclatures: (e.g. 3-letters ISO code)
country_name(x=c("UK","Estados Unidos","Zaire","C#te d^ivoire"), to= "ISO3")
#When multiple arguments are provided to the - to - argument, a data frame is returned:
country_name(x=c("UK","Estados Unidos","Zaire","C#te d^ivoire"), to= c("UN_en","UN_fr","ISO3"))
#This function can also be used to translate country names: (e.g. translating all to Chinese)
country_name(x=c("UK","Estados Unidos","Zaire","C#te d^ivoire"), to= "name_zh")