Movatterモバイル変換


[0]ホーム

URL:


02 - Leer bases

library(enaho)

Leer bases descargadas y combinarlas

Las bases descargads condescargar.inei() pueden serleídas conleer.inei(). El módulo y los períodos deben serespecificados. Si más de una base es leída, la función producirá unalista. Por ejemplo, si tenemos descargados los primeros dos trimestresde 2011 en una carpeta, podemos leer ambos trimestres:

dir<-system.file("extdata",package ="enaho")leido<-leer.inei(encuesta ="ENAHO",modulo =37,periodos =2011,tipo =c("t1","t2"),directorio = dir)#> Leyendo 2 archivos.#> Leyendo archivo 1 de 2.#> Leyendo archivo 2 de 2.leido#> $`2011_Modulo37_t1`#> # A tibble: 4,625 × 24#>    AÑO   MES   CONGLOME VIVIENDA HOGAR UBIGEO DOMINIO ESTRATO CODINFOR  P702#>    <chr> <chr> <chr>    <chr>    <chr> <chr>    <dbl>   <dbl> <chr>    <dbl>#>  1 2011  01    0007     049      11    010101       4       4 01           3#>  2 2011  01    0007     075      11    010101       4       4 02           5#>  3 2011  01    0027     047      11    010504       4       7 02           2#>  4 2011  01    0027     047      11    010504       4       7 02           3#>  5 2011  01    0027     047      11    010504       4       7 02           5#>  6 2011  01    0027     047      11    010504       4       7 02           5#>  7 2011  01    0027     108      11    010504       4       7 02           3#>  8 2011  01    0027     108      11    010504       4       7 02           4#>  9 2011  01    0027     109      11    010504       4       7 01           4#> 10 2011  01    0027     110      11    010504       4       7 02           4#> # ℹ 4,615 more rows#> # ℹ 14 more variables: P703 <dbl+lbl>, P704 <dbl+lbl>, P705 <dbl+lbl>,#> #   P7061 <dbl+lbl>, P7062 <dbl+lbl>, P7063 <dbl+lbl>, P7064 <dbl+lbl>,#> #   P7065 <dbl+lbl>, P706A1 <dbl+lbl>, P706A2 <dbl+lbl>, P706A3 <dbl+lbl>,#> #   P706A4 <dbl+lbl>, TICUEST01 <dbl+lbl>, FACTRIM <dbl>#>#> $`2011_Modulo37_t2`#> # A tibble: 3,940 × 24#>    AÑO   MES   CONGLOME VIVIENDA HOGAR UBIGEO DOMINIO ESTRATO CODINFOR  P702#>    <chr> <chr> <chr>    <chr>    <chr> <chr>    <dbl>   <dbl> <chr>    <dbl>#>  1 2011  04    0001     019      11    010101       4       4 02           1#>  2 2011  04    0001     019      11    010101       4       4 02           2#>  3 2011  04    0001     019      11    010101       4       4 02           3#>  4 2011  04    0001     019      11    010101       4       4 02           4#>  5 2011  04    0001     019      11    010101       4       4 02           5#>  6 2011  04    0047     032      11    010201       7       4 02           2#>  7 2011  04    0047     032      11    010201       7       4 02           3#>  8 2011  04    0047     032      11    010201       7       4 02           4#>  9 2011  04    0047     069      22    010201       7       4 02           6#> 10 2011  04    0047     082      11    010201       7       4 02           1#> # ℹ 3,930 more rows#> # ℹ 14 more variables: P703 <dbl+lbl>, P704 <dbl+lbl>, P705 <dbl+lbl>,#> #   P7061 <dbl+lbl>, P7062 <dbl+lbl>, P7063 <dbl+lbl>, P7064 <dbl+lbl>,#> #   P7065 <dbl+lbl>, P706A1 <dbl+lbl>, P706A2 <dbl+lbl>, P706A3 <dbl+lbl>,#> #   P706A4 <dbl+lbl>, TICUEST01 <dbl+lbl>, FACTRIM <dbl>

Y, usandocombinar.inei() (o el argumentocombinar enleer.inei) podemos combinar ambostrimestres. También podemos especificar si sólo queremos combinar lasvariables comunes o todas las variables:

combinar.inei(x = leido,combinarsolocomunes =FALSE)#> # A tibble: 8,565 × 24#>    AÑO   MES   CONGLOME VIVIENDA HOGAR UBIGEO DOMINIO ESTRATO CODINFOR  P702#>  * <chr> <chr> <chr>    <chr>    <chr> <chr>    <dbl>   <dbl> <chr>    <dbl>#>  1 2011  01    0007     049      11    010101       4       4 01           3#>  2 2011  01    0007     075      11    010101       4       4 02           5#>  3 2011  01    0027     047      11    010504       4       7 02           2#>  4 2011  01    0027     047      11    010504       4       7 02           3#>  5 2011  01    0027     047      11    010504       4       7 02           5#>  6 2011  01    0027     047      11    010504       4       7 02           5#>  7 2011  01    0027     108      11    010504       4       7 02           3#>  8 2011  01    0027     108      11    010504       4       7 02           4#>  9 2011  01    0027     109      11    010504       4       7 01           4#> 10 2011  01    0027     110      11    010504       4       7 02           4#> # ℹ 8,555 more rows#> # ℹ 14 more variables: P703 <dbl+lbl>, P704 <dbl+lbl>, P705 <dbl+lbl>,#> #   P7061 <dbl+lbl>, P7062 <dbl+lbl>, P7063 <dbl+lbl>, P7064 <dbl+lbl>,#> #   P7065 <dbl+lbl>, P706A1 <dbl+lbl>, P706A2 <dbl+lbl>, P706A3 <dbl+lbl>,#> #   P706A4 <dbl+lbl>, TICUEST01 <dbl+lbl>, FACTRIM <dbl>

Leer bases directamente desde la web

Usandoleer.inei.web() podemos leer las basesdirectamente desde la web, aplicando las mismas reglas queleer.inei():

leer.inei.web(encuesta ="ENAHO",modulo =37,periodos =2011,tipo =c("t1"))#> Descargando 1 archivo.#> Leyendo 1 archivo.#> Leyendo archivo 1 de 1.#> # A tibble: 4,625 × 24#>    AÑO   MES   CONGLOME VIVIENDA HOGAR UBIGEO DOMINIO ESTRATO CODINFOR  P702#>    <chr> <chr> <chr>    <chr>    <chr> <chr>    <dbl>   <dbl> <chr>    <dbl>#>  1 2011  01    0007     049      11    010101       4       4 01           3#>  2 2011  01    0007     075      11    010101       4       4 02           5#>  3 2011  01    0027     047      11    010504       4       7 02           2#>  4 2011  01    0027     047      11    010504       4       7 02           3#>  5 2011  01    0027     047      11    010504       4       7 02           5#>  6 2011  01    0027     047      11    010504       4       7 02           5#>  7 2011  01    0027     108      11    010504       4       7 02           3#>  8 2011  01    0027     108      11    010504       4       7 02           4#>  9 2011  01    0027     109      11    010504       4       7 01           4#> 10 2011  01    0027     110      11    010504       4       7 02           4#> # ℹ 4,615 more rows#> # ℹ 14 more variables: P703 <dbl+lbl>, P704 <dbl+lbl>, P705 <dbl+lbl>,#> #   P7061 <dbl+lbl>, P7062 <dbl+lbl>, P7063 <dbl+lbl>, P7064 <dbl+lbl>,#> #   P7065 <dbl+lbl>, P706A1 <dbl+lbl>, P706A2 <dbl+lbl>, P706A3 <dbl+lbl>,#> #   P706A4 <dbl+lbl>, TICUEST01 <dbl+lbl>, FACTRIM <dbl>

Leer sólo algunas variables

Debido a que las bases pueden ser muy grandesse recomiendasólo leer las variables requeridas. Para eso podemos usarvariablesxperiodo() que nos indicará qué variables estánpresentes en cada período:

variablesxperiodo(modulo =37,periodos =c(2011,2024),directorio = dir,tipo ="t1")#>       Nombre 2011_t1 2024_t1#> 1        AÑO       1       1#> 2        MES       1       1#> 3   CONGLOME       1       1#> 4   VIVIENDA       1       1#> 5      HOGAR       1       1#> 6     UBIGEO       1       1#> 7    DOMINIO       1       1#> 8    ESTRATO       1       1#> 9   CODINFOR       1       1#> 10      P702       1       1#> 11      P703       1       1#> 12      P704       1       1#> 13      P705       1       1#> 14     P7061       1       1#> 15     P7062       1       1#> 16     P7063       1       1#> 17     P7064       1       1#> 18     P7065       1       1#> 19    P706A1       1       1#> 20    P706A2       1       1#> 21    P706A3       1       1#> 22    P706A4       1       1#> 23 TICUEST01       1       1#> 24   FACTRIM       1       0#> 25    P706A5       0       1#> 26    FACTOR       0       1

Así podemos saber qué variables están disponibles y sólo leer las quenecesitamos conleer.inei() pero no conleer.inei.web():

vars<-c("AÑO","UBIGEO","DOMINIO","ESTRATO","P702","FACTRIM","FACTOR")leer.inei(modulo =37,periodos =c(2011,2024),directorio = dir,tipo ="t1",columnas = vars)#> Leyendo 2 archivos.#> Leyendo archivo 1 de 2.#> Leyendo archivo 2 de 2.#> $`2011_Modulo37_t1`#> # A tibble: 4,625 × 6#>    AÑO   UBIGEO DOMINIO ESTRATO  P702 FACTRIM#>    <chr> <chr>    <dbl>   <dbl> <dbl>   <dbl>#>  1 2011  010101       4       4     3    337.#>  2 2011  010101       4       4     5    337.#>  3 2011  010504       4       7     2    347.#>  4 2011  010504       4       7     3    347.#>  5 2011  010504       4       7     5    347.#>  6 2011  010504       4       7     5    347.#>  7 2011  010504       4       7     3    347.#>  8 2011  010504       4       7     4    347.#>  9 2011  010504       4       7     4    347.#> 10 2011  010504       4       7     4    347.#> # ℹ 4,615 more rows#>#> $`2024_Modulo37_t1`#> # A tibble: 6,083 × 6#>    AÑO   UBIGEO DOMINIO          ESTRATO                            P702  FACTOR#>    <chr> <chr>  <dbl+lbl>        <dbl+lbl>                          <chr>  <dbl>#>  1 2024  010101 4 [Sierra Norte] 4 [ De 20 000 a 49 999 habitantes] 03      442.#>  2 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   01      442.#>  3 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   04      789.#>  4 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   05      812.#>  5 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   02      789.#>  6 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   03      812.#>  7 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   03      812.#>  8 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   02      812.#>  9 2024  010307 7 [Selva]        5 [De 2 000 a 19 999 habitantes]   02      812.#> 10 2024  010701 7 [Selva]        4 [ De 20 000 a 49 999 habitantes] 04      770.#> # ℹ 6,073 more rows

También podemos leer sólo las variables comunes consolocomunes = TRUE. Sin embargo, podría haber variablesimportantes (como los pesos) que cambien de nombre entre períodos:

leer.inei(modulo =37,periodos =c(2011,2024),directorio = dir,tipo ="t1",solocomunes =TRUE)#> Leyendo 2 archivos.#> Leyendo archivo 1 de 2.#> Leyendo archivo 2 de 2.#> $`2011_Modulo37_t1`#> # A tibble: 4,625 × 23#>    AÑO   MES   CONGLOME VIVIENDA HOGAR UBIGEO DOMINIO ESTRATO CODINFOR  P702#>    <chr> <chr> <chr>    <chr>    <chr> <chr>    <dbl>   <dbl> <chr>    <dbl>#>  1 2011  01    0007     049      11    010101       4       4 01           3#>  2 2011  01    0007     075      11    010101       4       4 02           5#>  3 2011  01    0027     047      11    010504       4       7 02           2#>  4 2011  01    0027     047      11    010504       4       7 02           3#>  5 2011  01    0027     047      11    010504       4       7 02           5#>  6 2011  01    0027     047      11    010504       4       7 02           5#>  7 2011  01    0027     108      11    010504       4       7 02           3#>  8 2011  01    0027     108      11    010504       4       7 02           4#>  9 2011  01    0027     109      11    010504       4       7 01           4#> 10 2011  01    0027     110      11    010504       4       7 02           4#> # ℹ 4,615 more rows#> # ℹ 13 more variables: P703 <dbl+lbl>, P704 <dbl+lbl>, P705 <dbl+lbl>,#> #   P7061 <dbl+lbl>, P7062 <dbl+lbl>, P7063 <dbl+lbl>, P7064 <dbl+lbl>,#> #   P7065 <dbl+lbl>, P706A1 <dbl+lbl>, P706A2 <dbl+lbl>, P706A3 <dbl+lbl>,#> #   P706A4 <dbl+lbl>, TICUEST01 <dbl+lbl>#>#> $`2024_Modulo37_t1`#> # A tibble: 6,083 × 23#>    AÑO   MES   CONGLOME VIVIENDA HOGAR UBIGEO DOMINIO     ESTRATO CODINFOR P702#>    <chr> <chr> <chr>    <chr>    <chr> <chr>  <dbl+lbl>   <dbl+l> <chr>    <chr>#>  1 2024  01    015024   069      11    010101 4 [Sierra … 4 [ De… 01       03#>  2 2024  01    015040   089      11    010307 7 [Selva]   5 [De … 01       01#>  3 2024  01    015040   110      11    010307 7 [Selva]   5 [De … 02       04#>  4 2024  01    015040   110      11    010307 7 [Selva]   5 [De … 02       05#>  5 2024  01    015040   132      11    010307 7 [Selva]   5 [De … 01       02#>  6 2024  01    015040   132      11    010307 7 [Selva]   5 [De … 01       03#>  7 2024  01    015040   132      11    010307 7 [Selva]   5 [De … 01       03#>  8 2024  01    015040   153      11    010307 7 [Selva]   5 [De … 01       02#>  9 2024  01    015040   153      11    010307 7 [Selva]   5 [De … 01       02#> 10 2024  01    015052   012      11    010701 7 [Selva]   4 [ De… 02       04#> # ℹ 6,073 more rows#> # ℹ 13 more variables: P703 <dbl+lbl>, P704 <dbl+lbl>, P705 <dbl+lbl>,#> #   P7061 <dbl+lbl>, P7062 <dbl+lbl>, P7063 <dbl+lbl>, P7064 <dbl+lbl>,#> #   P7065 <dbl+lbl>, P706A1 <dbl+lbl>, P706A2 <dbl+lbl>, P706A3 <dbl+lbl>,#> #   P706A4 <dbl+lbl>, TICUEST01 <dbl+lbl>

[8]ページ先頭

©2009-2025 Movatter.jp