I have a dataset, df, where I wish to sum and groupby the type along with the date:
date size type
1/1/2020 1 a
1/1/2020 1 a
1/1/2020 1 a
1/1/2020 2 b
1/1/2020 5 b
1/1/2020 6 b
2/1/2020 20 a
2/1/2020 21 a
2/1/2020 10 a
2/1/2020 1 b
2/1/2020 4 b
2/1/2020 5 b
Desired output
(grouping by type and date to find sum)
date size type
1/1/2020 3 a
2/1/2020 51 a
1/1/2020 13 b
2/1/2020 10 b
This is what I am doing:
library(plyr)
ddply(df, .(date, type), (sum))
dput
structure(list(Date = c("1/1/2020", "1/1/2020", "1/1/2020", "1/1/2020",
"1/1/2020", "1/1/2020", "2/1/2020", "2/1/2020", "2/1/2020", "2/1/2020",
"2/1/2020", "2/1/2020"), size = c(1L, 1L, 1L, 2L, 5L, 6L, 20L,
21L, 10L, 1L, 4L, 5L), type = c("a", "a", "a", "b", "b", "b",
"a", "a", "a", "b", "b", "b")), class = "data.frame", row.names = c(NA,
-12L))