3
I am working with election data for mayors in Brazil and would like to select in my database only data related to municipalities based on two conditions:
- Municipalities where the dispute took place only between two candidates and
- Municipalities where these two only candidates were a man and a woman
My data frame follows this type:
Candidato <- c('Alberto', 'Alessandra', ' Cassio', 'Roberta', 'Denis', 'Flavia', 'Jefferson', 'Henrique', 'Paulo')
Municipio <- c('A', 'A', 'B', 'B', 'B', 'C', 'C', 'D', 'D')
Genero <- c('M', 'F', 'M', 'F', 'M', 'F', 'M', 'M', 'M')
dados <- data.frame (Candidato, Municipio, Genero)
I would like to have a result respecting the above conditions as follows:
Candidato Municipio Genero
Alberto A M
Alessandra A F
Flavia C F
Jefferson C M
Wow, buddy. The code didn’t work :( Just returned me the same dataframe. I appreciate your contribution
– phill
I updated my answer with the data frame that the function returned. The question data frame has 4 different municipalities. My code excludes the Cadidatos of City D, which has both male candidates. You can retain the code?
– Filipe Lauar
I had forgotten to put the restriction to have only 2 candidates, I edited the answer.
– Filipe Lauar