Skip to content

Commit

Permalink
v0.0.1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDeto committed Aug 23, 2020
1 parent fb078d8 commit 82277b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
19 changes: 14 additions & 5 deletions R/add_geom.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#'
#' @examples
#' \donttest{
#' pobre_x_dpto <- get_estimation_mean(variable = "pobre06", by.x = "dpto", level = "h") %>%
#' pobre_x_dpto <- get_estimation_mean(variable = "pobre06", by.x = "nomdpto", level = "h") %>%
#' dplyr::filter(pobre06 == "No pobre")
#' pobre_x_dpto_geo <- add_geom(data = pobre_x_dpto, unit = "Departamentos", variable = "dpto")
#' pobre_x_dpto_geo <- add_geom(data = pobre_x_dpto, unit = "Departamentos", variable = "nomdpto")
#' }

add_geom <- function (data, unit, variable, crs = 32721){
Expand All @@ -35,9 +35,18 @@ add_geom <- function (data, unit, variable, crs = 32721){

g <- geouy::load_geouy(unit, crs)
md <- geouy::metadata
name <- as.character(md[md$capa == unit, "name"])
g2 <- g %>% dplyr::select(name) %>%
rename("link" = name) %>% mutate(link = as.numeric(link))

if(is.character(data[[variable]])){
name <- as.character(md[md$capa == unit, "name"])
g2 <- g %>% dplyr::select(name) %>%
rename("link" = name) %>% mutate(link = as.character(link))
data <- left_join(g2, data, by = c("link" = variable))
} else {
cod <- as.character(md[md$capa == unit, "cod"])
g2 <- g %>% dplyr::select(cod) %>%
rename("link" = cod) %>% mutate(link = as.numeric(link))
data <- left_join(g2, data %>% mutate(link = as.numeric(!!!rlang::syms(variable))), by = "link")
}
return(data)
}

4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Para estimar una variable, por ejemplo, pobre06 que ya viene en la ECH calculada

pobre_x_dpto <- get_estimation_mean(data = ech19, # Indico el data.frame
variable = "pobre06", # La variable a estimar
by.x = "dpto", # La variable de agrupación
by.x = "nomdpto", # La variable de agrupación
by.y = NULL, # Se permite otra variable de agrupación
domain = NULL, # Se podría indicar un dominio
level = "h", # Defino que lo haga a nivel de hogar
Expand All @@ -160,7 +160,7 @@ pobre_x_dpto <- pobre_x_dpto %>% filter(pobre06 == "Pobre")

pobre_x_dpto_geo <- add_geom(data = pobre_x_dpto, # Los datos en una unidad geográfica de entre las opciones
unit = "Departamentos", # Unidad de agregación de los datos
variable = "dpto") # Variable correspondiente a los códigos a la unidad
variable = "nomdpto") # Variable correspondiente a los códigos a la unidad

```

Expand Down
4 changes: 2 additions & 2 deletions man/add_geom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82277b4

Please sign in to comment.