Parcial

rm(list=ls())
library(xtable)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
ruta<-"D:/Dropbox/SantoTomas/20161/Estadística Exploratoria/CorteIII/Parcial III"

setwd(ruta)

load(file = "BDsParcialFinal.RData")

attach(Personas)
attach(Vivienda)
## The following objects are masked from Personas:
## 
##     AREA, DIRECTORIO, DPTO, fex_c_2011, HOGAR, MES, ORDEN, REGIS,
##     SECUENCIA_P
# Punto 1
tabla1<-prop.table(table(P6050,P6100),1)*100
print.xtable(xtable(tabla1),type = "html",comment = F)
Contributivo (EPS)? Especial ? (Fuerzas Armadas, Ecopetrol, universidades públic Subsidiado? (EPS-S) No sabe, no informa
Jefe (a) del hogar 56.68 5.76 37.51 0.06
Pareja, esposo(a), cónyuge, compañero(a) 57.40 5.35 37.25 0.00
Hijo(a), hijastro(a) 48.38 4.04 47.55 0.04
Nieto(a) 41.50 2.99 55.49 0.02
Otro pariente 42.44 2.87 54.48 0.21
Empleado(a) del servicio doméstico y sus parientes 28.73 0.00 71.27 0.00
Pensionista 65.08 3.17 31.75 0.00
Trabajador 42.86 0.00 57.14 0.00
Otro no pariente 40.15 4.13 55.72 0.00
# Punto 2
P6008rec<-P6008
P6008rec<-replace(P6008rec,P6008rec %in% 5:20,5)
tabla2<-prop.table(table(P6008rec,P4030S1A1),1)*100
print.xtable(xtable(tabla2),type = "html",comment = F)
Conexión Pirata Bajo - Bajo Bajo Medio - Bajo Medio Medio - Alto Alto No sabe o cuenta con planta eléctrica
1 0.34 23.24 33.81 28.78 9.94 2.57 0.97 0.34
2 0.25 22.84 34.57 27.60 10.37 2.91 1.47 0.00
3 0.28 24.70 37.84 27.04 7.26 1.98 0.83 0.08
4 0.39 29.12 37.60 24.48 6.57 1.38 0.47 0.00
5 0.72 38.69 35.10 20.15 3.99 0.91 0.33 0.12
# Punto 3
detach(Personas)
detach(Vivienda)

Base<-full_join(Vivienda,Personas,by=c("DIRECTORIO","SECUENCIA_P","ORDEN"))

db3<-Base[Base$P6220 %in% c("Universitario","Postgrado") & Base$P5210S16=="Sí",]
aggregate(formula = P5210S16~P6220,data = db3,FUN = "length")
##           P6220 P5210S16
## 1 Universitario     1081
## 2     Postgrado      594
# Punto 4
db4<-subset(Base,  subset =  Base$P5090=="Propia, la están pagando")
aggregate(formula = P6040~P6020,data = db4,FUN = "mean")
##    P6020    P6040
## 1 Hombre 46.35729
## 2  Mujer 48.19392