-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#------------------------------------------------------------------------------# | ||
|
||
# UN stats year book data processing | ||
|
||
#------------------------------------------------------------------------------# | ||
|
||
|
||
|
||
if (Sys.getenv("USERNAME") == "Leonardo"){ | ||
projectFolder <- "C:/Users/Leonardo/Documents/GitHub/dime-r-training" | ||
dropbox <- "C:/Users/Leonardo/Dropbox/Work/WB/R Training/R training" | ||
|
||
} | ||
|
||
if (Sys.getenv("USERNAME") == "WB519128"){ | ||
projectFolder <- file.path("C:/Users/WB519128/Documents/GitHub/dime-r-training") | ||
dropbox <- "C:/Users/WB519128/Dropbox/Work/WB/R Training/R training" | ||
|
||
} | ||
|
||
UNstatsDat <- file.path(dropbox,"Data/World/Raw/UN stats yearbook") | ||
|
||
|
||
#------------------------------------------------------------------------------# | ||
#### Load data #### | ||
|
||
pop <- read.csv(file.path(UNstatsDat, "T02_Pop.csv"), header = T, stringsAsFactors = F) | ||
int <- read.csv(file.path(UNstatsDat,"T29_Internet.csv"), header = T, stringsAsFactors = F) | ||
crime <- read.csv(file.path(UNstatsDat,"T12_Crime.csv"), header = T, stringsAsFactors = F) | ||
gdp <- read.csv(file.path(UNstatsDat,"T13_Gdp.csv"), header = T, stringsAsFactors = F) | ||
educ <- read.csv(file.path(UNstatsDat,"T07_Education.csv"), header = T, stringsAsFactors = F) | ||
teach <- read.csv(file.path(UNstatsDat,"T08_Teachers.csv"), header = T, stringsAsFactors = F) | ||
med <- read.csv(file.path(UNstatsDat,"T10_Health_Personnel.csv"), header = T, stringsAsFactors = F) | ||
|
||
#------------------------------------------------------------------------------# | ||
#### Basic cleaning #### | ||
|
||
treat <- | ||
function(x){ | ||
names(x) <- c("code", | ||
"country", | ||
"year", | ||
"var", | ||
"value", | ||
"coomments", | ||
"source") | ||
|
||
nonCountries <- c("Total, all countries or areas", | ||
"Sub-Saharan Africa", | ||
"Latin America & the Caribbean", | ||
"South-central Asia", | ||
"Australia and New Zealand", | ||
"Oceania", | ||
"Africa", | ||
"Northern Africa", | ||
"Eastern Africa", | ||
"Middle Africa", | ||
"Southern Africa", | ||
"Western Africa", | ||
"Americas", | ||
"Northern America", | ||
"Caribbean", | ||
"Central America", | ||
"South America", | ||
"Asia", | ||
"Central Asia", | ||
"Eastern Asia", | ||
"South-eastern Asia", | ||
"Southern Asia", | ||
"Western Asia", | ||
"Europe", | ||
"Eastern Europe", | ||
"Northern Europe", | ||
"Southern Europe", | ||
"Western Europe", | ||
"Melanesia") | ||
|
||
x <- x[!(x$country %in% nonCountries),] | ||
x <- x[x$year > 2014,] | ||
return(x) | ||
} | ||
|
||
|
||
|
||
pop <- treat(pop) | ||
int <- treat(int) | ||
crime <- treat(crime) | ||
gdp <- treat(gdp) | ||
educ <- treat(educ) | ||
teach <-treat(teach) | ||
med <- treat(med) | ||
|
||
#------------------------------------------------------------------------------# | ||
#### Population #### | ||
|
||
pop$coomments <- NULL | ||
pop$source <- NULL | ||
|
||
keepVarspop <- c("Population mid-year estimates (millions)", | ||
"Sex ratio (males per 100 females)") | ||
|
||
pop <- pop[pop$var == keepVarspop,] | ||
|
||
|
||
pop <- spread(pop, | ||
key = var, | ||
value = value) | ||
|
||
|
||
#names(pop) <- | ||
|
||
#------------------------------------------------------------------------------# | ||
#### Population #### | ||
|
||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
country,code | ||
Norway,578 | ||
Denmark,208 | ||
Iceland,352 | ||
Switzerland,756 | ||
Finland,246 | ||
Netherlands,528 | ||
Canada,124 | ||
New Zealand,554 | ||
Sweden,752 | ||
Australia,36 | ||
Israel,376 | ||
Costa Rica,188 | ||
Austria,40 | ||
United States,840 | ||
Ireland,372 | ||
Germany,276 | ||
Belgium,56 | ||
Luxembourg,442 | ||
United Kingdom,826 | ||
Chile,152 | ||
United Arab Emirates,784 | ||
Brazil,76 | ||
Czech Republic,203 | ||
Argentina,32 | ||
Mexico,484 | ||
Singapore,702 | ||
Malta,470 | ||
Uruguay,858 | ||
Guatemala,320 | ||
Panama,591 | ||
France,250 | ||
Thailand,764 | ||
Taiwan,158 | ||
Spain,724 | ||
Qatar,634 | ||
Colombia,170 | ||
Saudi Arabia,682 | ||
Trinidad and Tobago,780 | ||
Kuwait,414 | ||
Slovakia,703 | ||
Bahrain,48 | ||
Malaysia,458 | ||
Nicaragua,558 | ||
Ecuador,218 | ||
El Salvador,222 | ||
Poland,616 | ||
Uzbekistan,860 | ||
Italy,380 | ||
Russia,643 | ||
Belize,84 | ||
Japan,392 | ||
Lithuania,440 | ||
Algeria,12 | ||
Latvia,428 | ||
South Korea,410 | ||
Moldova,498 | ||
Romania,642 | ||
Bolivia,68 | ||
Turkmenistan,795 | ||
Kazakhstan,398 | ||
North Cyprus,196 | ||
Slovenia,705 | ||
Peru,604 | ||
Mauritius,480 | ||
Cyprus,196 | ||
Estonia,233 | ||
Belarus,112 | ||
Libya,434 | ||
Turkey,792 | ||
Paraguay,600 | ||
Hong Kong,344 | ||
Philippines,608 | ||
Serbia,688 | ||
Jordan,400 | ||
Hungary,348 | ||
Jamaica,388 | ||
Croatia,191 | ||
Kosovo, | ||
China,156 | ||
Pakistan,586 | ||
Indonesia,360 | ||
Venezuela,862 | ||
Montenegro,499 | ||
Morocco,504 | ||
Azerbaijan,31 | ||
Dominican Republic,214 | ||
Greece,300 | ||
Lebanon,422 | ||
Portugal,620 | ||
Bosnia and Herzegovina,70 | ||
Honduras,340 | ||
Macedonia,807 | ||
Somalia,706 | ||
Vietnam,704 | ||
Nigeria,566 | ||
Tajikistan,762 | ||
Bhutan,64 | ||
Kyrgyzstan,417 | ||
Nepal,524 | ||
Mongolia,496 | ||
South Africa,710 | ||
Tunisia,788 | ||
Palestinian Territories,275 | ||
Egypt,818 | ||
Bulgaria,100 | ||
Sierra Leone,694 | ||
Cameroon,120 | ||
Iran,364 | ||
Albania,8 | ||
Bangladesh,50 | ||
Namibia,516 | ||
Kenya,404 | ||
Mozambique,508 | ||
Myanmar,104 | ||
Senegal,686 | ||
Zambia,894 | ||
Iraq,368 | ||
Gabon,266 | ||
Ethiopia,231 | ||
Sri Lanka,144 | ||
Armenia,51 | ||
India,356 | ||
Mauritania,478 | ||
Congo (Brazzaville),178 | ||
Georgia,268 | ||
Congo (Kinshasa),180 | ||
Mali,466 | ||
Ivory Coast,384 | ||
Cambodia,116 | ||
Sudan,729 | ||
Ghana,288 | ||
Ukraine,804 | ||
Uganda,800 | ||
Burkina Faso,854 | ||
Niger,562 | ||
Malawi,454 | ||
Chad,148 | ||
Zimbabwe,716 | ||
Lesotho,426 | ||
Angola,24 | ||
Afghanistan,4 | ||
Botswana,72 | ||
Benin,204 | ||
Madagascar,450 | ||
Haiti,332 | ||
Yemen,887 | ||
South Sudan,728 | ||
Liberia,430 | ||
Guinea,324 | ||
Togo,768 | ||
Rwanda,646 | ||
Syria,760 | ||
Tanzania,834 | ||
Burundi,108 | ||
Central African Republic,140 | ||
Puerto Rico,630 | ||
Suriname,740 | ||
Somaliland Region, | ||
Laos,418 | ||
Comoros,174 | ||
Oman,512 | ||
Somaliland region, | ||
Swaziland,748 | ||
Djibouti,262 |