R/get_P_tot_2d.R

#' Makes P_tot_2d from pop3d.
#' 
#' @param pop3d The 3 dimensional dataframe of population.
#' 
#' @examples
#' get_P_tot_2d(pop3d)
#' @keywords internal

get_P_tot_2d= function(pop3d){
  
  dn1 = dimnames(pop3d)[[1]]
  dn2 = dimnames(pop3d)[[2]]
  
  P_tot_2d = rep(NA, length(dn1)*length(dn2) )
  dim(P_tot_2d)=c(length(dn1),length(dn2) )
  for (adm in 1:length(dn1)){
    for (year in  1:length(dn2) ){
      P_tot_2d[adm,year] = sum(pop3d[adm,year,], na.rm=T)
    }
  } 
  rownames(P_tot_2d)=dn1
  colnames(P_tot_2d)=dn2
  
  return(P_tot_2d)
}
arranhamlet/popvac_package documentation built on May 10, 2019, 1:48 p.m.