3
I’m having trouble manipulating a TSE bank. The part below the code matters it:
library(tidyverse)
locais_vot_SP <- read_delim("https://raw.githubusercontent.com/camilagonc/votacao_secao/master/locais_vot_SP.csv",
locale = locale(encoding = "ISO-8859-1"),
delim = ",",
col_names = F) %>%
filter(X4 == "VINHEDO")
names(locais_vot_SP) <- c("num_zona",
"nome_local",
"endereco",
"nome_municipio",
"secoes",
"secoes_esp")
As can be noticed, the variable data secoes
are not properly organised, as different information is aggregated in the same cell.
secoes
196ª; 207ª; 221ª; 231ª;
197ª; 211ª; 230ª; 249ª;
With the following code, I started to fix the problem:
locais_vot_SP <- locais_vot_SP %>% mutate(secoes = gsub("ª", "", secoes)) %>%
mutate(secoes_esp = gsub("ª", "", secoes_esp)) %>%
mutate(secoes_esp = gsub(";", "", secoes_esp)) %>%
mutate(secoes = gsub("Da ", "", secoes)) %>%
separate_rows(secoes, sep = ";") %>%
mutate(secoes = unlist(strsplit(locais_vot_SP$secoes, ";")))
So I got the following:
secoes
32 à 38
100
121
What remains to be solved are the cells in which there are x à y
. How to get the following result?
secoes
32
33
34
35
36
37
38
...