I would like to summarize Votes by Party.
My table:
| State | Party | Votes | 
|---|---|---|
| NY | RP | 80 | 
| NY | DM | 20 | 
| CA | RP | 30 | 
| CA | DM | 70 | 
Expected:
| Party | Votes | 
|---|---|
| RP | 110 | 
| DM | 90 | 
This doesnt work for me:
data <- data %>% group_by(Party) %>% summarise(Votos)
Thanks!
Use the sum() function within summarise
library(dplyr)
df %>% 
  group_by(Party) %>% 
  summarise(Votes = sum(Votes, na.rm = TRUE))
 Party Votes
  <chr> <int>
1 DM       90
2 RP      110
If you want to have sorted:
df %>% 
  group_by(Party) %>% 
  summarise(Votes = sum(Votes, na.rm = TRUE)) %>% 
  arrange(desc(Votes))
  Party Votes
  <chr> <int>
1 RP      110
2 DM       90
