R/get_p_prop3d.R

#' Makes get_p_prop3d from pop3d and P_tot_2d.
#' 
#' @param pop3d The 3 dimensional dataframe of population.
#' @param P_tot_2d The 2 dimensional dataframe of the proportion of the population.
#' @examples
#' get_p_prop3d(pop3d,P_tot_2d)
#' @keywords internal

get_p_prop3d = function(pop3d, P_tot_2d){
  
  dn1<-dimnames(pop3d)[[1]]
  dn2<-dimnames(pop3d)[[2]]
  dn3<-dimnames(pop3d)[[3]]
  
  p_prop3d<-rep(NA, dim(pop3d)[1]*dim(pop3d)[2]*dim(pop3d)[3])
  dim(p_prop3d)<-dim(pop3d)
  for(adm in 1:length(dn1)){
    for (year in 1:length(dn2)){
      for (a in 1:length(dn3)){
        p_prop3d[adm,year,a]<-pop3d[adm, year, a]/P_tot_2d[adm, year]
      }
    }
  }
  dimnames(p_prop3d)[[1]]<-dn1
  dimnames(p_prop3d)[[2]]<-dn2
  dimnames(p_prop3d)[[3]]<-dn3
  
  return(p_prop3d)
}
arranhamlet/popvac_package documentation built on May 10, 2019, 1:48 p.m.