Created
January 21, 2015 14:52
-
-
Save jtrecenti/368d6fa2bb16decae58f to your computer and use it in GitHub Desktop.
Associa bd do carlos cinelli com cadmun do pacote abjutils (fonte IBGE)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(abjutils) | |
| library(tidyr) | |
| library(stringr) | |
| f <- download.file('https://dl.dropboxusercontent.com/u/44201187/dados.rds', method='wget', 'cc.rds') | |
| cc <- readRDS('cc.rds') | |
| cc <- cc %>% | |
| mutate(Municipio=str_trim(Municipio)) %>% | |
| unite(municipio_uf, Municipio, Estado, sep='@') | |
| data(cadmun) | |
| cadmun_limpo <- cadmun %>% | |
| filter(SITUACAO != 'IGNOR') %>% | |
| unite(municipio_uf, MUNNOME, uf, sep='@') | |
| # bizarro: todos os municipios bateram! | |
| # mostra quais municipios de cc ainda não estão em cadmun_limpo (0) | |
| cc %>% | |
| distinct(municipio_uf) %>% | |
| anti_join(cadmun_limpo, 'municipio_uf') | |
| # mostra quais municipios de cadmun_limpo ainda não estão em cc (475) | |
| cadmun_limpo %>% | |
| anti_join(cc, 'municipio_uf') | |
| merged_cadmun_cc <- cc %>% | |
| inner_join(cadmun_limpo, 'municipio_uf') %>% | |
| separate(municipio_uf, c('municipio', 'uf'), sep='@') | |
| saveRDS(merged_cadmun_cc, 'merged_cadmun_cc.rds') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment