Last active
October 30, 2022 23:23
-
-
Save gabrielzanlorenssi/019e9bf3dcacd0ab464d210950799c75 to your computer and use it in GitHub Desktop.
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
# Pacotes ----------------------------------------------------------------- | |
library(tidyverse) | |
library(jsonlite) | |
# Configurar -------------------------------------------------------------- | |
#-- codigo pleito | |
# pleito = 544 # 1t !! | |
pleito = 545 # 2t !! (usar esse no dia 30/10) !! | |
#-- url | |
url = paste0("https://resultados.tse.jus.br/oficial/ele2022/", pleito, | |
"/dados-simplificados/br/br-c0001-e000", pleito, "-r.json") | |
pres_br <- fromJSON(url, simplifyDataFrame = TRUE) | |
#-- votacao | |
votos <- pres_br %>% | |
.[["cand"]] %>% | |
tbl_df() %>% | |
mutate(voto=as.numeric(vap), | |
pct=voto/sum(voto, na.rm=T)) %>% | |
select(n, nm, pvap, voto) %>% | |
mutate(pvap=paste0(pvap, "%")) | |
# total comparecimento | |
votos_totais <- pres_br %>% .[["c"]] %>% as.numeric() | |
# validos | |
votos_validos <- pres_br %>% .[["vvc"]] %>% as.numeric() | |
# brancos nulos | |
votos_nulos <- pres_br %>% .[["tvn"]] %>% as.numeric() | |
# validos | |
votos_brancos <- pres_br %>% .[["vb"]] %>% as.numeric() | |
#abs | |
abstencoes <- pres_br %>% .[["a"]] %>% as.numeric() | |
#apurado | |
eleitorado_apurado <- pres_br %>% .[["ea"]] | |
eleitorado_apurado <- as.numeric(eleitorado_apurado) * 100 / 156454011 | |
#-- votos | |
votos | |
votos_totais | |
votos_validos | |
votos_nulos | |
votos_brancos | |
abstencoes | |
eleitorado_apurado | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment