【发布时间】:2019-07-21 05:02:35
【问题描述】:
这里是我的数据
mydata=structure(list(doc_date = structure(c(7L, 9L, 4L, 10L, 2L, 5L,
8L, 1L, 3L, 6L), .Label = c("01.06.2018", "06.04.2018", "08.07.2018",
"14.03.2018", "20.04.2018", "21.09.2018", "24.01.2018", "25.05.2018",
"28.02.2018", "28.03.2018"), class = "factor"), shop_id = c(67885L,
67885L, 67885L, 67885L, 67885L, 67885L, 67885L, 67885L, 67885L,
67885L), shop_code = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = "02293НСК", class = "factor"), product_id = c(11622L,
11622L, 11622L, 11622L, 11622L, 11622L, 11622L, 11622L, 11622L,
11622L), product_group_id = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L), city_id = c(9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L),
fin_centre_id = c(15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L), return_count = c(2L, 3L, 1L, 1L, 1L, 1L, 3L, 1L,
3L, 2L)), .Names = c("doc_date", "shop_id", "shop_code",
"product_id", "product_group_id", "city_id", "fin_centre_id",
"return_count"), class = "data.frame", row.names = c(NA, -10L
))
我如何为组 shop_code+product_id 聚合列 return_count 每个月,按枢轴格式sum。
I.E.输出
jan feb march apr may jun jul aug sept oct nov dec
1 2 3 2 2 3 1 3 0 2 0 0 0
这个话题不是重复的 Aggregate / summarize multiple variables per group (e.g. sum, mean) 因为我需要枢轴格式
【问题讨论】:
-
你尝试了什么?
-
您能澄清一下“数据透视格式”是什么意思吗?
标签: r dplyr data.table lubridate