to_iso: Convert countries to ISO codes

Description Usage Arguments Details Examples

View source: R/to_iso.R

Description

Return a vector of ISO country codes for a given vector of country names.

Usage

1
to_iso3(x, output="iso3")

Arguments

x

character vector of country names.

output

one of c("iso3", "iso2", "clean"). Determines output as either ISO-3 or ISO-2 codes, or a cleaned country name.

Details

The function includes a preset lookup table of unclean country names, clean country names, and corresponding ISO 3166-1 alpha-2 & alpha-3 codes (2 and 3-letter country codes). Input vectors are first cleaned, which includes removing punctuation and converting to lower-case. Then they are matched to the unclean country names. This step allows for differently-spelled country names to be reconcilled correctly. For example, "United Kingdom" and "Great Britain" will both be matched to the same codes.

Output can also be returned as a vector of "clean" country names. In the above example, both names would be matched to "United Kingdom of Great Britain and Northern Ireland".

If an input value is not in the lookup table, a warning will notify of at which position the unmatched value is, and return the original value in that position in the output.

Examples

1
2
3
4
5
x = c("United States of America", "U.S.A.", "Canda", "Canada", "United Kingdom","Great Britain", "xyz")

to_iso(x, output="iso3")

to_iso(x, output="clean")

NRGI/nrgiR documentation built on Dec. 14, 2018, 3:02 p.m.