countrycode (version 1.1.0)

countrycode: Converts long country names into one of many different coding schemes. Translates from one scheme to another. Converts country name or coding scheme to the official short English country name. Creates a new variable with the name of the continent or region to which each country belongs.

Description

Converts long country names into one of many different coding schemes. Translates from one scheme to another. Converts country name or coding scheme to the official short English country name. Creates a new variable with the name of the continent or region to which each country belongs.

Usage

countrycode(sourcevar, origin, destination, warn = TRUE, nomatch = NA,
  custom_dict = NULL, custom_match = NULL, origin_regex = FALSE)

Arguments

sourcevar

Vector which contains the codes or country names to be converted (character or factor)

origin

Coding scheme of origin (string such as "iso3c" enclosed in quotes ""): type "?codelist" for a list of available codes.

destination

Coding scheme of destination (string such as "iso3c" enclosed in quotes ""): type `?codelist` for a list of available codes.

warn

Prints unique elements from sourcevar for which no match was found

nomatch

When countrycode fails to find a match for the code of origin, it fills-in the destination vector with nomatch. The default behavior is to fill non-matching codes with NA. If nomatch = NULL, countrycode tries to use the origin vector to fill-in missing values in the destination vector. nomatch must be either NULL, of length 1, or of the same length as sourcevar.

custom_dict

A data frame which supplies custom country codes. Variables correspond to country codes, observations must refer to unique countries. When countrycode uses a user-supplied dictionary, no sanity checks are conducted. The data frame format must resemble countrycode::codelist.

custom_match

A named vector which supplies custom origin and destination matches that will supercede any matching default result. The name of each element will be used as the origin code, and the value of each element will be used as the destination code.

origin_regex

Logical: When using a custom dictionary, if TRUE then the origin codes will be matched as regex, if FALSE they will be matched exactly. When using the default dictionary (dictionary = NULL), origin_regex will be ignored.

Examples

# NOT RUN {
# ISO to Correlates of War
countrycode(c('USA', 'DZA'), 'iso3c', 'cown')
# English to ISO
countrycode('Albania', 'country.name', 'iso3c')
# German to French
countrycode('Albanien', 'country.name.de', 'iso.name.fr')
# }