3
Suppose I have the following database
>data
zona candidato votos
1 A 100
1 B 20
2 A 30
2 B 15
I want, using dplry, the following matrix
>nova
zona votos_zona votosA votosB
1 120 100 20
2 45 30 15
I tried something like this
nova <- data %>%
group_by(zona) %>%
summarise(votos_zona= sum(votos),
votosA = ,
votosB = )
But I can’t complete the code
I liked the solution ... it serves to add other variables in relation to candidates. Thank you
– orrillo
yesterday I checked the code and everything worked out... today when I went around again, a one-line matrix appears... it’s as if I didn’t use group_by(zone)... it gave me only the total sum of each variable I asked: votos_zonevotosB 1 165 130 35
– orrillo
@Vasco for some reason you carried the
dplyr
first and then the packageplyr
in second. When you do this gives error because the functionsummarise
ofplyr
mask the function ofdplyr
. Restarts the R and loads only thedplyr
or carry first theplyr
and then thedplyr
(in that order). See this Soen question: http://stackoverflow.com/questions/26106146/using-dplyr-to-summarise-by-group/26106218#26106218– Carlos Cinelli