R/separate_locations.R

#' Separates locations
#'
#' @param adm0 Country ISO code.
#' @param loc.id GADM1 identifier of the location.
#' @examples
#' separate.locations("AGO",1054)
#' @keywords internal

## function to work out the specific locations:
separate.locations <- function(adm0, loc.id) {
  loc.id<-gsub(" ", "", loc.id)  
  loc.id<-strsplit(unlist(strsplit(loc.id, ";")), ":")
  mat<-matrix(NA, nrow = length(loc.id), ncol = 3) ## max resolution of adm level = 3
  for(i in 1:length(loc.id)) { 
    for(j in 1:3) mat[i, j]<-as.numeric(loc.id[[i]][j])
  }
  mat<-data.frame(adm0<-adm0, mat, stringsAsFactors = FALSE)
  colnames(mat)<-c("country.code", "adm1", "adm2", "adm3")
  return(mat)
} 
arranhamlet/popvac_package documentation built on May 10, 2019, 1:48 p.m.