R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

# Cargando data
load("C:/Users/naye/Downloads/info_FGT.RData")
library(kableExtra)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
## 
##     group_rows
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
###Construya funciones personalizadas en R, que permitan el cálculo de los indicadores indicadores de la familia FGT, utilícelas para calcular todos los indicadores, si el umbral de pobreza "z":

## A. 300 u.m. y presente los resultados totales por municipio.

### Indicadores de la Familia Foster Greer & Thorbecke
# Tasa de Pobreza (Head Count):
indicador_h1 <-
  function(z, muni) {
    info_FGT %>%
      filter(municipio == muni) %>%
      as.data.frame() -> filtro1
    nrow(filtro1) -> n
    info_FGT %>%
      group_by(municipio == muni) %>%
      filter(ingreso < z, municipio == muni) %>%
      as.data.frame() -> filtro2
    nrow(filtro2) -> q
    Head_Count <- q / n
  }
indicador_h1(300, "A") %>% kable(digits = 2,
                                caption = "Indicador 1 Municipio A",
                                col.names = "H") %>% kable_material()
Indicador 1 Municipio A
H
0.29
indicador_h1(300, "B") %>% kable(digits = 2,
                                caption = "Indicador 1 Municipio B",
                                col.names = "H") %>% kable_material()
Indicador 1 Municipio B
H
0.5
indicador_h1(300, "C") %>% kable(digits = 2,
                                caption = "Indicador 1 Municipio C",
                                col.names = "H") %>% kable_material()
Indicador 1 Municipio C
H
0.43

B. 350 u.m. y presente los resultados totales por municipio y por zona

# Tasa de Pobreza (Head Count):
indicador_h2 <-
  function(z, muni) {
    info_FGT %>%
      filter(municipio == muni) %>%
      as.data.frame() -> filtro1
    nrow(filtro1) -> n
    info_FGT %>%
      group_by(municipio == muni) %>%
      filter(ingreso < z, municipio == muni) %>%
      as.data.frame() -> filtro2
    nrow(filtro2) -> q
    Head_Count2 <- q / n
  }
indicador_h2(350, "A") %>% kable(digits = 2,
                                caption = "Indicador 1 Municipio A",
                                col.names = "H") %>% kable_material()
Indicador 1 Municipio A
H
0.29
indicador_h2(350, "B") %>% kable(digits = 2,
                                caption = "Indicador 1 Municipio B",
                                col.names = "H") %>% kable_material()
Indicador 1 Municipio B
H
0.5
indicador_h2(350, "C") %>% kable(digits = 2,
                                caption = "Indicador 1 Municipio C",
                                col.names = "H") %>% kable_material()
Indicador 1 Municipio C
H
0.5
#Indice de brecha de pobreza
#Foster de orden 2