Country_Name
Character
Algeria (58)
Algeria : 58 (0.49%)
Australia (58)
Australia : 58 (0.49%)
Austria (58)
Austria : 58 (0.49%)
Bahamas, The (58)
Bahamas, The: 58 (0.49%)
Bangladesh (58)
Bangladesh : 58 (0.49%)
Belgium (58)
Belgium : 58 (0.49%)
(Other) (11,426)
(Other) : 11,426 (97.04%)
Not NA: 100.00%
NA0 (0.00%)
Unique Values256
Min Length4
Max Length52
Country_iso3c
Character
AUS (58)
AUS : 58 (0.49%)
AUT (58)
AUT : 58 (0.49%)
BDI (58)
BDI : 58 (0.49%)
BEL (58)
BEL : 58 (0.49%)
BEN (58)
BEN : 58 (0.49%)
BFA (58)
BFA : 58 (0.49%)
(Others) (11,426)
(Others): 11,426 (97.04%)
Not NA: 100.00%
NA0 (0.00%)
Unique Values256
Min Length3
Max Length3
Country_iso2c
Character
AT (58)
AT : 58 (0.49%)
AU (58)
AU : 58 (0.49%)
BD (58)
BD : 58 (0.49%)
BE (58)
BE : 58 (0.49%)
BF (58)
BF : 58 (0.49%)
(Others) (9,089)
(Others): 9,089 (77.20%)
Not NA: 79.66%
NA: 20.34%
NA2,395 (20.34%)
Unique Values208
Min Length2
Max Length2
Year
Integer
Not NA: 100.00%
NA0 (0.00%)
Min1,960
Max2,017
Median1,993
Average1,992
Std Dev16.16
Population
Numeric
Not NA: 100.00%
NA0 (0.00%)
Min8,913
Max7.5110e+9
Median8,927,000
Average2.5840e+8
Std Dev763,169,579.44
GDP
Numeric
Not NA: 100.00%
NA0 (0.00%)
Min8,824,000
Max8.0680e+13
Median1.4940e+10
Average1.0390e+12
Std Dev4,672,471,798,175.16
6 Columns   11,774 Rows
6 Columns   11,774 Rows
# Set libPaths.
.libPaths("/Users/kannishida/.exploratory/R/3.6")

# Load required packages.
library(MESS)
library(dslabs)
library(janitor)
library(lubridate)
library(hms)
library(tidyr)
library(stringr)
library(readr)
library(forcats)
library(RcppRoll)
library(dplyr)
library(tibble)
library(bit64)
library(exploratory)

# Steps to produce GDP
`GDP` <- exploratory::read_delim_file("/Users/kannishida/Downloads/API_NY.GDP.MKTP.CD_DS2_en_csv_v2_10134290/API_NY.GDP.MKTP.CD_DS2_en_csv_v2_10134290.csv" , ",", quote = "\"", skip = 4 , col_names = TRUE , na = c('','NA') , locale=readr::locale(encoding = "UTF-8", decimal_mark = "."), trim_ws = TRUE , progress = FALSE) %>%
  readr::type_convert() %>%
  exploratory::clean_data_frame() %>%
  select(`Country Code`, `2017`) %>%
  filter(!is.na(`2017`))

# Steps to produce GDP_tidy
`GDP_tidy` <- exploratory::read_delim_file("/Users/kannishida/Downloads/API_NY.GDP.MKTP.CD_DS2_en_csv_v2_10134290/API_NY.GDP.MKTP.CD_DS2_en_csv_v2_10134290.csv" , ",", quote = "\"", skip = 4 , col_names = TRUE , na = c('','NA') , locale=readr::locale(encoding = "UTF-8", decimal_mark = "."), trim_ws = TRUE , progress = FALSE) %>%
  readr::type_convert() %>%
  exploratory::clean_data_frame() %>%
  select(-`Indicator Name`, -`Indicator Code`, -X63) %>%
  gather(Year, GDP, `1960`:`2017`, na.rm = TRUE, convert = TRUE)

# Steps to produce the output
exploratory::read_excel_file( "/Users/kannishida/Dropbox/Data/country_population.xls", sheet = "Data", na = c('','NA'), skip=3, col_names=TRUE, trim_ws=TRUE, col_types="text") %>%
  readr::type_convert() %>%
  exploratory::clean_data_frame() %>%
  select(-`Indicator Name`, -`Indicator Code`) %>%
  gather(Year, Population, `1960`:`2018`, na.rm = TRUE, convert = TRUE) %>%
  left_join(GDP_tidy, by = c("Country Code" = "Country Code", "Year" = "Year")) %>%
  select(-`Country Name.y`) %>%
  filter(!is.na(GDP)) %>%
  mutate(Country_iso2c = countrycode(`Country Code`, origin="iso3c", destination="iso2c")) %>%
  rename(Country_Name = `Country Name.x`, Country_iso3c = `Country Code`) %>%
  reorder_cols(Country_Name, Country_iso3c, Country_iso2c)