df_tablas <- data.frame()
funcion1 <- function(n){
xx<-switch(n,"2006","2009","2011","2013","2015","2017","2020")
tanio <<- xx
v1 <- switch(n,"Homologacion_002","Homologacion_002","Homologacion_002","Homologacion_002","Homologacion_002","Homologacion_002","Homologacion_002")
if(xx==2006) {
eliminated <- casen_2006
c <- eliminated[,c(v1)]
anio <- 2006
}
if(xx==2009) {
eliminated <- casen_2009
c <- eliminated[,c(v1)]
anio <- 2009
}
if(xx==2011) {
eliminated <- casen_2011
c <- eliminated[,c(v1)]
anio <- 2011
}
if(xx==2013) {
eliminated <- casen_2013
c <- eliminated[,c(v1)]
anio <- 2013
}
if(xx==2015) {
eliminated <- casen_2015
c <- eliminated[,c(v1)]
anio <- 2015
}
if(xx==2017) {
eliminated <- casen_2017
c <- eliminated[,c(v1)]
anio <- 2017
}
if(xx==2020) {
eliminated <- casen_2020
c <- eliminated[,c(v1)]
anio <- 2020
}
################ -- frecuencia
expan<-switch(n,"EXPC","EXPC","expc_full","expc","expc_todas","expc","expc")
tabla_matp <-xtabs(eliminated[,(expan)]~c, data = eliminated)
tabla_matp <- as.data.frame(tabla_matp)
names(tabla_matp)[1] <- "categorias"
data_df1 <<- tabla_matp
################
}
for (n in 1:7){
funcion1(n)
assign(paste0("tabla_",tanio),data_df1)
}
tabla_f <- merge(tabla_2006, tabla_2009, by= "categorias", all.x = T, all.y = T)
tabla_f <- merge(tabla_f, tabla_2011, by= "categorias", all.x = T, all.y = T)
tabla_f <- merge(tabla_f, tabla_2013, by= "categorias", all.x = T, all.y = T)
tabla_f <- merge(tabla_f, tabla_2015, by= "categorias", all.x = T, all.y = T)
tabla_f <- merge(tabla_f, tabla_2017, by= "categorias", all.x = T, all.y = T)
tabla_f <- merge(tabla_f, tabla_2020, by= "categorias", all.x = T, all.y = T)
colnames(tabla_f) <- c("Variable","2006","2009","2011","2013","2015","2017","2020")
tabla_f <- mutate_all(tabla_f, ~replace(., is.na(.), 0))
tabla_t <- tabla_f
tabla_t$a2007 <- NA
tabla_t$a2008 <- NA
tabla_t$a2010 <- NA
tabla_t$a2012 <- NA
# tabla_t$a2013 <- NA
tabla_t$a2014 <- NA
# tabla_t$a2015 <- NA
tabla_t$a2016 <- NA
tabla_t$a2018 <- NA
tabla_t$a2019 <- NA
tabla_t <- tabla_t[,c("Variable","2006","a2007","a2008","2009","a2010","2011","a2012","2013","a2014","2015","a2016","2017","a2018","a2019","2020")]
receptaculo <- data.frame()
for (n in 1:nrow(tabla_t)) {
calculado <- na.approx(c(tabla_t[n,c(2:ncol(tabla_t))]))
receptaculo <- rbind(receptaculo,calculado)
}
receptaculo <- cbind(tabla_t$Variable,receptaculo)
colnames(receptaculo) <- c("categorias",paste0(seq(2006,2020,1)))
################
datatable(receptaculo, extensions = 'Buttons', escape = FALSE, rownames = TRUE,
options = list(dom = 'Bfrtip',
buttons = list('colvis', list(extend = 'collection',
buttons = list(
list(extend='copy'),
list(extend='excel',
filename = 'ruralidad'),
list(extend='pdf',
filename= 'ruralidad')),
text = 'Download')), scrollX = TRUE))%>%
formatRound(columns=c(paste0(seq(2006,2020,1))) ,mark = "", digits=0)