-1

I have a dataframe deliv with the columns date, name, region and count. Now I want to want to group by date and name so that region doesn't matter and count is summed up for every date/name-combination.

My idea was to use dplyr:

library(dplyr)
df = deliv %>%
  group_by(date) 

So not even that works; df is exactly the same as deliv. I don't know how to debug that piece any further. How do I group by (two) columns but the right way?

Standard
  • 1,450
  • 17
  • 35
  • 1
    Does this answer your question? [Aggregate / summarize multiple variables per group (e.g. sum, mean)](https://stackoverflow.com/questions/9723208/aggregate-summarize-multiple-variables-per-group-e-g-sum-mean) – user438383 Apr 26 '21 at 14:08
  • or this https://stackoverflow.com/questions/1660124/how-to-sum-a-variable-by-group – NicolasH2 Apr 26 '21 at 14:13
  • `group_by` in itself doesn't do anything (visually). You need to tell it to do something after that. – Ronak Shah Apr 26 '21 at 14:27

1 Answers1

1

Look at summarise:


library(dplyr)
df = deliv %>%
  group_by(date,name) %>%
  summarise( total_count = sum(count) )

Sirius
  • 5,224
  • 2
  • 14
  • 21