I'm trying to use across() or another tidyverse function to simplify the lines that follow the general line of output.partyA = sum(x.partyA) - sum(y.partyA)
.
An example of one of the lines that I did to simplify the number of lines was: across(matches("^Seats_P_...$"), ~ .x / Dist_Mag, .names = "{str_replace({.col}, '_P_', '_P_Pct_')}"),
.
Here's what I am trying to simplify:
df %>%
group_by(MMD) %>%
summarise(
N = n(),
#taken out for clarity,
DFP_RCV_DEM = sum(Seats_RCV_Pct_DEM) - sum(SVP_DEM),
DFP_RCV_REP = sum(Seats_RCV_Pct_REP) - sum(SVP_REP),
DFP_RCV_SCT = sum(Seats_RCV_Pct_SCT) - sum(SVP_SCT),
DFP_RCV_WRT = sum(Seats_RCV_Pct_WRT) - sum(SVP_WRT),
DFP_RCV_LBT = sum(Seats_RCV_Pct_LBT) - sum(SVP_LBT),
DFP_RCV_UND = sum(Seats_RCV_Pct_UND) - sum(SVP_UND)
) %>%
ungroup()