0

I am using group_by and sum but instead of providing group by the result I am getting only one value.

Data :

County     Date        GW
Moore   2018-06-18     375
Moore   2018-06-18     639
Nash    2017-12-14     358
Nash    2017-12-14     583
Wake    2017-11-07     170
Wake    2018-01-09     423
Wake    2017-04-07     342
Wake    2017-04-07     1470


NC_county <- NC_county %>% group_by(County,Date) %>% 
  summarise(Gross_Weight = sum(GW)) 

I am looking for a result like:

County     Date        GW
Moore   2018-06-18     1014
Nash    2017-12-14     941
Wake    2017-11-07     170
Wake    2018-01-09     423
Wake    2017-04-07     1812
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Running your example, I got exactly what you said you wanted. We probably need to see something like `dput(head(NC_county))` in order to know what's going on. – Ben Bolker Sep 11 '20 at 04:33
  • 1
    Maybe you have `plyr` loaded. Try with `dplyr::summarise` instead. – Ronak Shah Sep 11 '20 at 04:36
  • Would happen have `plyr` loaded as well? It is known to interact with the `group_by` function. – Paul van Oppen Sep 11 '20 at 04:36
  • structure(list(County = c("Moore", "Moore", "Nash", "Nash", "Wake", "Wake"), Posting_Date = structure(c(1529294400, 1529294400, 1513227600, 1513227600, 1510030800, 1515474000), class = c("POSIXct", "POSIXt" ), tzone = "America/New_York"), Gross_Weight = c(375, 639, 358, 583, 170, 423)), row.names = c(NA, 6L), class = "data.frame") – Shubhra Paul Sep 11 '20 at 04:36
  • @PaulvanOppen, RonakShah, pretty sure you guys are right. – Ben Bolker Sep 11 '20 at 04:36
  • Yes. I loaded **plyr** too. – Shubhra Paul Sep 11 '20 at 04:42

0 Answers0