Skip to contents

get_brazil_state_code() returns a vector with the Brazilian Institute of Geography and Statistics (IBGE) codes for Brazilian states.

Usage

get_brazil_state_code(x = NULL)

Arguments

x

(optional) An atomic vector containing the names of Brazilian states or federal units. Municipality codes are also supported. If NULL, returns a vector with all state codes (default: NULL).

Value

An integer vector with the IBGE codes of Brazilian states.

Details

The data from this function is based on data from the Brazilian Institute of Geography and Statistics (IBGE, n.d.).

References

Instituto Brasileiro de Geografia e Estatística. (n.d.). Território [Territory] [Dataset]. SIDRA. https://sidra.ibge.gov.br/territorio

Examples

get_brazil_state_code()
#>                Acre             Alagoas               Amapá            Amazonas 
#>                  12                  27                  16                  13 
#>               Bahia               Ceará    Distrito Federal      Espírito Santo 
#>                  29                  23                  53                  32 
#>               Goiás            Maranhão         Mato Grosso  Mato Grosso do Sul 
#>                  52                  21                  51                  50 
#>        Minas Gerais                Pará             Paraíba              Paraná 
#>                  31                  15                  25                  41 
#>          Pernambuco               Piauí      Rio de Janeiro Rio Grande do Norte 
#>                  26                  22                  33                  24 
#>   Rio Grande do Sul            Rondônia             Roraima      Santa Catarina 
#>                  43                  11                  14                  42 
#>           São Paulo             Sergipe           Tocantins 
#>                  35                  28                  17 

get_brazil_state_code("ac")
#> [1] 12
#> [1] 12 # Expected

get_brazil_state_code("acre")
#> [1] 12
#> [1] 12 # Expected

get_brazil_state_code(3550308) # São Paulo
#> [1] 35
#> [1] 35 # Expected

get_brazil_state_code(35503081) # >7 digits
#> [1] NA
#> [1] NA # Expected

get_brazil_state_code(3912345) # Non-existent state code
#> [1] NA
#> [1] NA # Expected