add_countrycode: Add country code

View source: R/add_countrycode.R

add_countrycodeR Documentation

Add country code

Description

Wrapper function for countrycode::countrycode() enabling piped execution.

Usage

add_countrycode(data, ..., warn = TRUE, na.rm = FALSE)

add_countrycode_(data, origin, destination, warn = TRUE, na.rm = FALSE)

Arguments

data

A data frame.

...

Key-value pairs for NSE of origin and destination parameters.

warn

Prints unique elements from sourcevar for which no match was found.

na.rm

If TRUE, remove ambiguously matched rows.

origin

Named scalar linking source column to source coding scheme. See countrycode::countrycode() for details.

destination

Named scalar linking destination column name to destination coding scheme. See countrycode::countrycode() for details.

Value

A data frame.

Author(s)

Michaja Pehl

Examples

library(dplyr)
data <- tibble(
    country = c('Belgium', 'Narnia', 'Russia', 'Botswana'),
    data    = 1:4)

data %>% add_countrycode(country = country.name, m49.code = un)
data %>% add_countrycode_(c('country' = 'country.name'), 'iso3c',
                          warn = FALSE, na.rm = TRUE)

pik-piam/quitte documentation built on April 26, 2024, 12:58 a.m.