#' Populates a cleaned UN WPP interpolated csv at adm2
#' @param popage Cleaned UN WPP interpolated csv
#' @examples
#' popperadm2(WPPintAGO)
#' @keywords internal
popperadm2<-function(popage){
#Subset populations to country
popcountryISO<-poptab[as.character(poptab$ISO) %in% as.character(popage$ISO),]
#Calculate the population at adm2 for all ages
adm2popages<-sapply(1:dim(popage)[1], function(x){
popcountrylevel<-popage[x,-which(names(popage) %in% c("LocID","Location","VarID","Variant","Time","SexID","Sex","ISO"))]
eachadm2<-sapply(1:length(popcountryISO$prop_pop), function(y){
as.numeric(unlist(popcountrylevel*popcountryISO$prop_pop[y]))
})
eachadm2<-t(eachadm2)
df<-cbind(popage[x,c("Location","LocID","Time","ISO")],"adm1_name"=as.character(popcountryISO$adm1_name),"adm1_id"=as.character(popcountryISO$adm1_id),
"adm2_name"=as.character(popcountryISO$adm2_name),"adm2_id"=popcountryISO$adm2_id,eachadm2)
for(z in which((names(df) %in% c("Location","LocID","Time","ISO","adm1_name","adm1_id","adm2_name","adm2_id"))==FALSE)){
df[,z]<-as.numeric(df[,z])
}
df$adm1_name<-as.character(df$adm1_name)
df$adm2_name<-as.character(df$adm2_name)
df$ISO<-as.character(df$ISO)
print(x)
df
})
#Save as dataframe and fix names
df2<-data.frame(matrix(unlist(t(adm2popages)), ncol = 109, byrow = FALSE),stringsAsFactors=FALSE)
colnames(df2)<-c("Country","Country.code","Date","ISO","adm1_name","adm1_id","adm2_name","adm2_id",
paste("X",0:100,sep=""))
#Remove NA's as 0
df2[is.na(df2)]<-0
#Translate to numbers not characters
for(x in 9:length(df2)){
df2[,x]<-as.numeric(df2[,x])*1000
}
df2
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.