-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-Mujeres_Trabajando.R
45 lines (39 loc) · 1.63 KB
/
1-Mujeres_Trabajando.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Sexo Femenino y trabajando con ingreso y con empleo / poblacion total
#Conexiones
library(RMySQL)
library(tidyverse)
con <- src_mysql(dbname = "censo2012",
host = Sys.getenv("MYSQL_HOST"),
user = Sys.getenv("MYSQL_USER"),
password = Sys.getenv("MYSQL_PASS")
)
#Inicio querys
#Generando ID_W
geoid <- tbl(con,"idgeo") %>%
select(FOLIO,NVIV,COM,DTO,AREA,ZONA,MZ,LOCALIDAD,ENTIDAD,SECTOR) %>%
collect(n=Inf) %>%
mutate(ID_W=paste(COM,sprintf("%02d", DTO),AREA,ifelse(AREA==1, sprintf("%03d",ZONA), ifelse(AREA==2, sprintf("%03d",LOCALIDAD), 0)),ifelse(AREA==1, sprintf("%03d",MZ), ifelse(AREA==2, sprintf("%03d",ENTIDAD), 0)),sep="")) %>%
select(FOLIO,NVIV,ID_W)
#Obteniendo variables desde el servidor y haciendo filter
#Primero se filtran los casos 1 y 2 condicion laboral trabajando o con trabajo 2 mujer por NVIV y FOLIO
mujerestrabajando <-tbl(con,"poblacion") %>%
select(FOLIO,NVIV,P36,P19,P20C) %>% collect(n=Inf) %>%
left_join(geoid, by=c("FOLIO"="FOLIO","NVIV"="NVIV")) %>%
filter(P19==2) %>%
filter(P36==1|P36==2|P36==4) %>%
filter(P20C>=16) %>%
filter(P20C<=60) %>%
group_by(ID_W) %>%
summarize(count = n())
totalmujeres <- tbl(con,"poblacion") %>%
select(FOLIO,NVIV,P19,P20C) %>%
collect(n=Inf) %>%
left_join(geoid, by=c("FOLIO"="FOLIO","NVIV"="NVIV")) %>%
filter(P19==2) %>%
filter(P20C>=16) %>%
filter(P20C<=60) %>%
group_by(ID_W) %>%
summarize(total = n())
final <- left_join(mujerestrabajando, totalmujeres, by=c("ID_W"="ID_W")) %>% mutate(value = count/total)
#Cleaning
rm(list=c("geoid","totalmujeres","mujerestrabajando"))