Skip to contents

Extract region codes (for aggregation levels ccaa, prov, mun, municipal districts and census sections) for a given poll station code provided by Spanish Ministry of Interior (MIR) and Spanish Statistical Office (INE)

Usage

extract_code(id_INE_poll_station, level = "mun", full_cod = FALSE)

Arguments

id_INE_poll_station

poll station code. It should be a string vector with tokens between 18 and 19 characters with 5 '-' according to the INE/MIR format").

level

aggregation level, for which we want to extract codes. It should be taken from the following values: 'ccaa', 'prov', 'mun', 'mun-district', 'sec' or 'poll_station'

full_cod

flag to indicate if codes should be provided in a full format (including codes of more aggregated levels) or not. Defaults to FALSE.

Value

A string code subtract from the whole code the properly id for the aggregation level required.

Author

Javier Alvarez-Liebana, David Pereiro-Pol, Mafalda Gonzalez-Gonzalez and Irene Bosque-Gala.

Examples


## Correct examples

# Code for Adra ("003"), from province of Almeria ("04") and ccaa of
# Andalucia ("01"), first municipal district ("01"), census
# sections district ("004") and poll station "B"
id_INE_poll_station <- "01-04-003-01-004-B"

extract_code(id_INE_poll_station, level = "mun", full_cod = FALSE)
#> [1] "003"
extract_code(id_INE_poll_station, level = "mun", full_cod = TRUE)
#> [1] "01-04-003"
extract_code(id_INE_poll_station, level = "prov", full_cod = FALSE)
#> [1] "04"
extract_code(id_INE_poll_station, level = "prov", full_cod = TRUE)
#> [1] "01-04"
extract_code(id_INE_poll_station, level = "ccaa", full_cod = FALSE)
#> [1] "01"
extract_code(id_INE_poll_station, level = "ccaa", full_cod = TRUE)
#> [1] "01"
extract_code(id_INE_poll_station, level = "mun_district",
             full_cod = TRUE)
#> [1] "01-04-003-01"

# ----
# Incorrect examples
# ----

if (FALSE) { # \dontrun{
extract_code(id_INE_poll_station, level = "prov", full_cod = false)
extract_code(id_INE_poll_station, level = "province", full_cod = TRUE)
extract_code(id_INE_poll_station, level = "muni", full_cod = "all")
extract_code(id_INE_poll_station, level = "poll", full_cod = TRUE)
extract_code(id_INE_poll_station, level = "district", full_cod = TRUE)
} # }