【发布时间】:2020-02-28 10:33:50
【问题描述】:
R: 可以在 dcast 中添加汇总文件吗? 用户与月订单数。并在年度总结之间添加。
检查附加的屏幕截图(excel)以获得预期结果。
User Order_date
a 02-01-2017
b 02-02-2017
a 02-08-2017
c 02-05-2017
a 02-08-2017
s 02-06-2017
c 02-03-2017
s 02-04-2017
b 02-06-2017
c 02-11-2017
a 02-11-2017
s 02-11-2017
c 02-01-2018
s 02-01-2018
b 02-02-2018
b 02-10-2018
尝试生成报告但不显示在excel中显示的汇总值, 请检查代码和随附的屏幕截图。
library(data.table)
library(lubridate)
df$start_year_month <- format(df$Month_Due, "%Y-%m")
#dcast(setDT(df), user ~ factor(start_year_month, levels = 1:12), sum, drop = FALSE)
datatable(dcast(df, user ~ start_year_month), filter = 'top',fun.aggregate = ???? )
【问题讨论】: