1

My code is the one shown below:

  New_promo_store%>%
  mutate(MiniTotal = rowSums(.[4:17], na.rm = TRUE)) %>%
  group_by(`ITEM#`) %>%
  mutate(Total = sum(MiniTotal, na.rm = TRUE))

However, instead of adding per ITEM#, it's adding the whole column together

This code was working fine just last week.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Piccinin1992
  • 237
  • 3
  • 12

1 Answers1

3

It could be that the package plyr was also loaded along with dplyr and the mutate from plyrmasked the other mutate. An option is to specify dplyr:: or do this on a fresh R session with only dplyr loaded

library(dplyr)
New_promo_store%>%
   dplyr::mutate(MiniTotal = rowSums(.[4:17], na.rm = TRUE)) %>%
    group_by(`ITEM#`) %>%
    dplyr::mutate(Total = sum(MiniTotal, na.rm = TRUE))
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    I have found many instances where `plyr` has no business being loaded, as well. You (Piccinin1992) might investigate if you are actually using `plyr` in your code; if not, there should be no need to load it (therefore preempting this problem from the start). – r2evans May 25 '20 at 23:48
  • 1
    Worked, thanks r2evans and akrun. Forgot that package was loaded in as well. – Piccinin1992 May 25 '20 at 23:51