0

Lets say I have a df structured in the following way:

  Date          Country     Count
1/21/2020   Mainland China  1
1/21/2020   Mainland China  5
1/21/2020   Mainland China  2
1/21/2020   United States   2
1/21/2020   United States   3
1/23/2020   Mainland China  3
1/23/2020   Mainland China  6
1/23/2020   Mainland China  3
1/23/2020   United States   4
1/23/2020   United States   5

But instead I want something like this:

   Date         Country     N
1/21/2020   Mainland China  8
1/21/2020   United States   5
1/23/2020   Mainland China  12
1/23/2020   United States   9 

Where I want the sum of count WITHIN each Date + Country. How would I go about accomplishing this? (the df is actually much larger than the example here).

I have already tried group_by(date, country) and using aggregate(N ~ Date + Country, df, sum) but I keep getting something like this:

   Date         Country     N
1/21/2020   Mainland China  8
1/21/2020   United States   5
1/23/2020   Mainland China  20
1/23/2020   United States   14 

Hopefully this is clear.

Cory
  • 13
  • 3

0 Answers0