as_country_name
converts a vector of standardized country codes to
country names.
as_country_name( x, to = "en", from = "iso2c", short = TRUE, variant = FALSE, factor = is.factor(x) )
x | A character, factor, or numeric vector of country codes or names |
---|---|
to | Language code of country names desired. Defaults to |
from | Code format from which to convert. Defaults to |
short | Whether to use short alternative name when available. Can be
length 1 or the same length as |
variant | Whether to use variant alternative name when available. Can
be length 1 or the same length as |
factor | If |
A character or factor vector of country names. Warns if new NA
values are added.
as_country_name
takes a character, factor, or numeric vector of country
codes (or names in another standardized format) and converts them to
country names in the specified format. If you are trying to standardize an
existing set of names, see parse_country()
.
The default "en"
is
from Unicode Common Locale Data Repository (CLDR),
which aspires to use the most customary name
e.g. "Switzerland" instead of official ones, which are frequently awkward for
common usage, e.g. "Swiss Confederation". CLDR also supplies names in a huge
variety of languages, allowing for easy translation. Short and variant
alternates are available for some countries; if not, the function will fall
back to the standard form. See LICENSE file for terms of use.
Other name sets are available from
the UN Statistics Division(UNSD),
which maintains standardized names in English, Chinese, Russian, French,
Spanish, and Arabic, here named as "en_un"
etc.
the ISO, "en_iso"
and "fr_iso"
, and
"en_cia"
, which include many longer official forms and shorter
practical forms,
"en_cia_local"
, which includes transliterations, and
"en_cia_abbreviation"
, which includes commonly-used abbreviations.
See codes
for all options, or run DT::datatable(codes)
for a
searchable widget.
For converting standardized names to codes, use as_country_code()
.
For standardizing names to codes, use parse_country()
.
#> [1] "US" "Taiwan" "Myanmar" "Kosovo" "South Korea"# If passed a factor, will return a releveled one as_country_name(factor(c("US", "NF", "CD", "SJ")), short = FALSE, variant = TRUE)#> [1] United States Norfolk Island Congo (DRC) #> [4] Svalbard & Jan Mayen #> Levels: Congo (DRC) Norfolk Island Svalbard & Jan Mayen United States# Speaks a lot of languages, knows a lot of codes as_country_name(c("SAH", "PCN", "OMA", "JPN"), from = "fifa", to = "cy") # to Welsh#> [1] "Gorllewin Sahara" "Ynysoedd Pitcairn" "Oman" #> [4] "Japan"