I wish to sum the rows (here in this case seats of parties in parliament) but only if the party voted yes (here indicated by 1 for yes and 0 for no).
Example data frame:
cabinet <- c("A", "B", "C")
seats1 <- c(20, 30, 40)
seats2 <- c(10, 15, 5)
seats3 <- c(10, 5, 10)
vote1 <- c(1, 1, 1)
vote2 <- c(1, 0, 1)
vote3 <- c(1, 0, 0)
df <- data.frame(cabinet, seats1, seats2, seats3, vote1, vote2, vote3)
So each row represents a vote and I want the total seats of all parties that voted for yes. I should also mention that sometimes some vote values are missing.
Thank you for your help!