| to_iso | R Documentation |
Return a vector of ISO country codes for a given vector of country names.
to_iso3(x, output="iso3")
x |
character vector of country names. |
output |
one of |
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.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.