# Total male population (observed)
# This dataset is created on the fly as a sum of the age-specific population estimates popM

popMT <- local({
    #suppressPackageStartupMessages(library(data.table)) <- function(dataset) {
		year.cols <- grep('^[0-9]{4}', colnames(dataset), value = TRUE)
		name.col <- grep('^name$|^country$', colnames(dataset), value=TRUE)
		data.table::setnames(dataset, name.col, "name") # rename if necessary
		dataset[, c("country_code", "name", year.cols), 
		        with = FALSE][,lapply(.SD, sum, na.rm = TRUE), 
		                      by = c("country_code", "name")]

Try the wpp2017 package in your browser

Any scripts or data that you put into this service are public.

wpp2017 documentation built on May 2, 2019, 7:22 a.m.