I am trying to find a function which can perform the role of SUMIFS in excel without reduction of rows.
The expectation is to sum the values of a particular column for each of the duplicates in the other column.
For Example: 2M-MA Should be the sum of 44.4444 + 37.037 + 0.0000 which is 81.481
Can someone help me out with and tell me how can I use a pipe function to create this output.
Attached is the data frame I am working with.
structure(list(Model = c("2M-MA", "2M-MA", "2M-MA", "4M-MA",
"4M-MA", "4M-MA"), `12NC's` = c("X12-57", "X12-78", "X12-65",
"X12-75", "X12-62", "X12-35"), `Avg Price` = c(17.5, 24.2, 110.4,
54.9, 23.5, 67.4), Act = c(45, 54, 21, 14, 33, 6), Fct = c(70,
20, 55, 80, 18, 2), Value_Act = c(787.5, 1306.8, 2318.4, 768.6,
775.5, 404.4), Value_Fct = c(1225, 484, 6072, 4392, 423, 134.8
), FC = c(44.4444444444444, 37.037037037037, 0, 0, 54.5454545454546,
33.3333333333333), FC1 = c(44.4444444444444, 37.037037037037,
0, 0, 54.5454545454546, 33.3333333333333), SUMIF = c(81.4814814814815,
81.4814814814815, 81.4814814814815, 87.8787878787879, 87.8787878787879,
87.8787878787879)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-6L))
Attaching an Image for clarity:
The code which I was writing is:
Test1 <- read_excel("x/x/x/x/x/Test1.xlsx")
Test1 <- Test1 %>%
mutate(SUMIF = group_by(Model) %>%
sum(FC1))