-3

Hi I have a dataset that looks approximatively like this

Store shelf Revenue week
3       1     5054   52-2016
3       2     3564   52-2016
3       3     1260   52-2016
15      1     7000   1-2017
15      2     1236   1-2017
15      3     4596   1-2017

My aim is to make sum of revenues by store and week using dplyr

data %>% group_by(store, week) %>% mutate(R_sum = sum(Revenue))

Is this working? Thanks in advance

Ric S
  • 9,073
  • 3
  • 25
  • 51
Blueberry
  • 363
  • 1
  • 2
  • 10

1 Answers1

-1

Use summarise for tasks like these instead of mutate

data %>%
  group_by(Store, week) %>%
  summarise(R_sum = sum(Revenue))

# A tibble: 2 x 3
# Groups:   Store [2]
#   Store week    R_sum
#   <int> <chr>   <int>
# 1     3 52-2016  9878
# 2    15 1-2017  12832
Ric S
  • 9,073
  • 3
  • 25
  • 51