How to filter data using shortcut names
Source:vignettes/articles/filter_data_shortcuts.Rmd
filter_data_shortcuts.Rmd
Instead of using numeric codes, it is possible to use certain
shortcut names when the filter
argument is passed. However,
for a better performance is recommended to use numeric codes. The
available shortcuts for variables are shown below.
Shortcut | Variable ID | Comment |
---|---|---|
nac | 349 | National |
ccaa | 70 | Autonomous Communities |
prov | 115 | Provinces |
mun | 19 | Municipalities |
island | 20 | Islands |
isla | 20 | Islands |
group | 762 | CPI groups |
grupo | 762 | CPI groups |
subgroup | 763 | CPI subgroups |
subgrupo | 763 | CPI subgroups |
class | 764 | CPI class |
clase | 764 | CPI class |
subclass | 765 | CPI subclass |
subclase | 765 | CPI subclass |
heading | 270 | CPI headings |
rubrica | 270 | CPI headings |
specialgroup | 269 | CPI special groups |
grupoespecial | 269 | CPI special groups |
datatype | 3 | Type of data |
tipodato | 3 | Type of data |
sex | 18 | Sex |
sexo | 18 | Sex |
age1 | 355 | Simple age |
edad1 | 355 | Simple age |
aget | 356 | Age totals |
edadt | 356 | Age totals |
ageg | 360 | Age groups |
edadg | 360 | Age groups |
ages | 357 | Age semi-intervals |
edads | 357 | Age semi-intervals |
age | 355, 356, 357, 360 | Age wrapper |
edad | 355, 356, 357, 360 | Age wrapper |
generation | 612 | Generation/ages |
generacion | 612 | Generation/ages |
nationality | 141 | Nationality |
nacionalidad | 141 | Nationality |
birthcountry | 431, 432 | Country of birth |
paisnacimiento | 431, 432 | Country of birth |
birthplace | 97 | Place of birth |
lugarnacimiento | 97 | Place of birth |
effectscorr | 544 | Correction of effects |
efectoscorr | 544 | Correction of effects |
values | - | Values wrapper |
Filtering data from tables
To use a filter with shortcuts it is necessary to pass the argument
filter
using a shortcut as variable and a name as
value.
Example one
We are going to filter the table Índices nacionales: general y de grupos ECOICOP (Id 50902):
library(ineapir)
# Filter using shortcuts (CPI)
filter <- list(tipodato = "variación anual" , # variable id = 3
grupo = "índice general" # variable id = 762
)
# Request data using the filter
ipc <- get_data_table(idTable = 50902, filter = filter, unnest = TRUE,
tip = "A", nlast = 5, validate = FALSE)
ipc[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> Nombre T3_Periodo Anyo Valor
#> 1 Total Nacional. Índice general. Variación anual. M07 2024 2.8
#> 1.1 Total Nacional. Índice general. Variación anual. M06 2024 3.4
#> 1.2 Total Nacional. Índice general. Variación anual. M05 2024 3.6
#> 1.3 Total Nacional. Índice general. Variación anual. M04 2024 3.3
#> 1.4 Total Nacional. Índice general. Variación anual. M03 2024 3.2
Besides, we can also use the values wrapper.
# Filter with the values wrapper
filter <- list(values = c("variación anual" , "índice general"))
# Request data using the filter
ipc <- get_data_table(idTable = 50902, filter = filter, unnest = TRUE,
tip = "A", nlast = 5, validate = FALSE)
ipc[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> Nombre T3_Periodo Anyo Valor
#> 1 Total Nacional. Índice general. Variación anual. M07 2024 2.8
#> 1.1 Total Nacional. Índice general. Variación anual. M06 2024 3.4
#> 1.2 Total Nacional. Índice general. Variación anual. M05 2024 3.6
#> 1.3 Total Nacional. Índice general. Variación anual. M04 2024 3.3
#> 1.4 Total Nacional. Índice general. Variación anual. M03 2024 3.2
Example two
We are going to filter the table PIB pm Oferta (Indices de volumen encadenado) (Id 30679):
# Filter with the values wrapper (GDP)
filter <- list(values = c("producto interior", "datos ajustados", "variación anual"))
# Request data using the filter and shortcut = TRUE
pib <- get_data_table(idTable = 30679, filter = filter, unnest = TRUE,
tip = "A", nlast = 5, validate = FALSE)
pib[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> Nombre
#> 1 Total Nacional. Datos ajustados de estacionalidad y calendario. Producto interior bruto a precios de mercado. Variación anual. Índices de volumen encadenados.
#> 1.1 Total Nacional. Datos ajustados de estacionalidad y calendario. Producto interior bruto a precios de mercado. Variación anual. Índices de volumen encadenados.
#> 1.2 Total Nacional. Datos ajustados de estacionalidad y calendario. Producto interior bruto a precios de mercado. Variación anual. Índices de volumen encadenados.
#> 1.3 Total Nacional. Datos ajustados de estacionalidad y calendario. Producto interior bruto a precios de mercado. Variación anual. Índices de volumen encadenados.
#> 1.4 Total Nacional. Datos ajustados de estacionalidad y calendario. Producto interior bruto a precios de mercado. Variación anual. Índices de volumen encadenados.
#> T3_Periodo Anyo Valor
#> 1 T2 2024 2.8873
#> 1.1 T1 2024 2.5806
#> 1.2 T4 2023 2.1685
#> 1.3 T3 2023 1.9417
#> 1.4 T2 2023 1.9659
Example three
We are going to filter the table Población residente por fecha, sexo y edad (desde 1971) (Id 56934)
# Filter with the values wrapper (population)
filter <- list(values = c("todas las edades", "total"))
# Request data using the filter
pob <- get_data_table(idTable = 56934, filter = filter, unnest = TRUE,
tip = "A", nlast = 5, validate = FALSE)
pob[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> Nombre
#> 1 Total Nacional. Todas las edades. Total. Población. Número.
#> 1.1 Total Nacional. Todas las edades. Total. Población. Número.
#> 1.2 Total Nacional. Todas las edades. Total. Población. Número.
#> 1.3 Total Nacional. Todas las edades. Total. Población. Número.
#> 1.4 Total Nacional. Todas las edades. Total. Población. Número.
#> T3_Periodo Anyo Valor
#> 1 1 de enero de 2023 48085361
#> 1.1 1 de octubre de 2022 47940295
#> 1.2 1 de julio de 2022 47781354
#> 1.3 1 de abril de 2022 47609145
#> 1.4 1 de enero de 2022 47486727
Filtering data from series
It is necessary to pass the argument filter
of the
get_data_series_filter()
function. We use a shortcut as
variable and a name as value.
Example one
# Filter with the values wrapper (CPI)
filter <- list(values = c("variación anual" , "índice general", "total nacional"))
# Request data using the filter
ipc <- get_data_series_filter(operation = "IPC", filter = filter,
periodicity = 1, unnest = TRUE, tip = "A",
validate = FALSE)
ipc[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> Nombre
#> 1 Total Nacional. Índice general. Variación anual.
#> 2 Total Nacional. Índice general. Variación anual. Impuestos constantes.
#> T3_Periodo Anyo Valor
#> 1 Julio 2024 2.8
#> 2 M06 2024 2.8
Example two
# Filter with the values wrapper (GDP)
filter <- list(values = c("producto interior", "datos ajustados",
"volumen encadenado", "variación anual"))
# Request data using the filter
pib <- get_data_series_filter(operation = "CNTR2010", filter = filter,
periodicity = 3, unnest = TRUE, tip = "A",
validate = FALSE)
pib[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> NULL
Example three
# Filter with the values wrapper combine with individual shortcuts (population)
filter <- list(values = c("todas las edades", "total nacional"), nacionalidad = "total",
sexo = "total", paisnacimiento = "total" )
# Request data using the filter
pob <- get_data_series_filter(operation = "ECP", filter = filter,
periodicity = 3, unnest = TRUE, tip = "A",
validate = FALSE)
pob[,c("Nombre", "T3_Periodo", "Anyo", "Valor")]
#> Nombre
#> 1 Total Nacional. Total. Todas las edades. Total. Total. Población. Número.
#> 2 Total Nacional. Total. Todas las edades. Total. Total. Población. Número.
#> T3_Periodo Anyo Valor
#> 1 T1 2023 48085361
#> 2 T1 2023 48085361