Skip to content
Snippets Groups Projects
Commit 003f98f4 authored by Jenny Bryan's avatar Jenny Bryan
Browse files

Fix country codes for North Korea

cc @dmi3kno
parent e292c73d
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,6 @@ Suggests:
dplyr,
ggplot2,
testthat
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
Imports:
tibble
# gapminder 0.3.0.9000
* The 3-letter and numeric country codes for "Korea, Dem. Rep." (Democratic People's Republic of Korea, a.k.a. North Korea) have been corrected to "PRK" (was "KOR") and 408 (was 410). Previously, this country was erroneously getting the codes for "Korea, Rep." (Republic of Korea, a.k.a. South Korea).
# gapminder 0.3.0
* `country_codes` is a new data frame that contains ISO 3166-1 country codes (#16 @jrebane).
......
......@@ -8,6 +8,10 @@ library(here)
library(gapminder)
library(tidyverse)
conflicted::conflict_prefer("filter", "dplyr")
packageVersion("countrycode")
country_codes <- tibble(
country = levels(gapminder_unfiltered$country)
)
......@@ -15,8 +19,26 @@ country_codes <- country_codes %>%
mutate(iso_alpha = countrycode(country, "country.name", "iso3c"),
iso_num = countrycode(country, "country.name", "iso3n"))
anyNA(country_codes$iso_alpha)
anyNA(country_codes$iso_num)
country_codes %>%
filter(is.na(iso_alpha) | is.na(iso_num))
## Netherlands Antilles is no longer a country and, apparently, countrycode
## v1.0.0 now reflects that
## Add it back to reflect reality during the years spanned by gapminder
netherlands_antilles <- country_codes$country == "Netherlands Antilles"
country_codes$iso_alpha[netherlands_antilles] <- "ANT"
country_codes$iso_num[netherlands_antilles] <- 530
## Sudan's numeric country code changed when South Sudan split off in 2011
## apparently, countrycode v1.0.0 now reflects that
## Add it back to reflect reality during the years spanned by gapminder
sudan <- country_codes$country == "Sudan"
country_codes$iso_num[sudan] <- 736
## manually correct codes for North Korea (Korea, Dem. Rep.)
north_korea <- country_codes$country == "Korea, Dem. Rep."
country_codes$iso_alpha[north_korea] <- "PRK"
country_codes$iso_num[north_korea] <- 408
save(
country_codes,
......
10\_iso-codes.R
================
jenny
2017-10-31
2018-09-24
``` r
library(countrycode)
......@@ -15,21 +15,28 @@ library(gapminder)
library(tidyverse)
```
## + ggplot2 2.2.1 Date: 2017-10-31
## + tibble 1.3.4 R: 3.4.1
## + tidyr 0.7.1 OS: macOS Sierra 10.12.6
## + readr 1.1.1 GUI: X11
## + purrr 0.2.3.9000 Locale: en_CA.UTF-8
## + dplyr 0.7.4 TZ: America/Vancouver
## + stringr 1.2.0.9000
## + forcats 0.2.0
## ── Attaching packages ───────────────────────────────────────── tidyverse 1.2.1 ──
## Warning: package 'dplyr' was built under R version 3.4.2
## ✔ ggplot2 3.0.0 ✔ purrr 0.2.5
## ✔ tibble 1.4.99.9004 ✔ dplyr 0.7.99.9000
## ✔ tidyr 0.8.1 ✔ stringr 1.3.1
## ✔ readr 1.2.0 ✔ forcats 0.3.0
## ── Conflicts ────────────────────────────────────────────────────
## ── Conflicts ──────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## * filter(), from dplyr, masks stats::filter()
## * lag(), from dplyr, masks stats::lag()
``` r
conflicted::conflict_prefer("filter", "dplyr")
```
## [conflicted] Will prefer dplyr::filter over any other package
``` r
packageVersion("countrycode")
```
## [1] '1.0.0'
``` r
country_codes <- tibble(
......@@ -38,19 +45,41 @@ country_codes <- tibble(
country_codes <- country_codes %>%
mutate(iso_alpha = countrycode(country, "country.name", "iso3c"),
iso_num = countrycode(country, "country.name", "iso3n"))
anyNA(country_codes$iso_alpha)
```
## [1] FALSE
## Warning in countrycode(country, "country.name", "iso3c"): Some values were not matched unambiguously: Netherlands Antilles
## Warning in countrycode(country, "country.name", "iso3n"): Some values were not matched unambiguously: Netherlands Antilles
``` r
anyNA(country_codes$iso_num)
country_codes %>%
filter(is.na(iso_alpha) | is.na(iso_num))
```
## [1] FALSE
## # A tibble: 1 x 3
## country iso_alpha iso_num
## <chr> <chr> <int>
## 1 Netherlands Antilles <NA> NA
``` r
## Netherlands Antilles is no longer a country and, apparently, countrycode
## v1.0.0 now reflects that
## Add it back to reflect reality during the years spanned by gapminder
netherlands_antilles <- country_codes$country == "Netherlands Antilles"
country_codes$iso_alpha[netherlands_antilles] <- "ANT"
country_codes$iso_num[netherlands_antilles] <- 530
## Sudan's numeric country code changed when South Sudan split off in 2011
## apparently, countrycode v1.0.0 now reflects that
## Add it back to reflect reality during the years spanned by gapminder
sudan <- country_codes$country == "Sudan"
country_codes$iso_num[sudan] <- 736
## manually correct codes for North Korea (Korea, Dem. Rep.)
north_korea <- country_codes$country == "Korea, Dem. Rep."
country_codes$iso_alpha[north_korea] <- "PRK"
country_codes$iso_num[north_korea] <- 408
save(
country_codes,
file = here("data", "country_codes.rdata")
......
......@@ -88,7 +88,7 @@ Japan JPN 392
Jordan JOR 400
Kazakhstan KAZ 398
Kenya KEN 404
Korea, Dem. Rep. KOR 410
Korea, Dem. Rep. PRK 408
Korea, Rep. KOR 410
Kuwait KWT 414
Latvia LVA 428
......
No preview for this file type
......@@ -88,7 +88,7 @@ Japan JPN 392
Jordan JOR 400
Kazakhstan KAZ 398
Kenya KEN 404
Korea, Dem. Rep. KOR 410
Korea, Dem. Rep. PRK 408
Korea, Rep. KOR 410
Kuwait KWT 414
Latvia LVA 428
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment