【发布时间】:2017-07-17 17:28:43
【问题描述】:
我有一个包含 5 列的数据集:
store_id year event item units
123 2015 sale_2 abc 2
234 2015 sale_3 def 1
345 2015 sale_2 xyz 5
我正在尝试将items 轮换出store_id, year, and event 以获得sum。比如
store_id year event abc def xyz
123 2015 sale_2 2 0 0
234 2015 sale_3 0 1 0
345 2015 sale_2 0 0 5
我无法找出最佳方法。通常我会在插入符号中使用 dummyVars 来执行此操作,但我需要总和而不是标志。我看过tapply,但它不能处理超过2个分组变量。
还有其他建议吗?
【问题讨论】:
-
看起来您的意思是将商店 345 改为商店 123,以便 5 + 2 = 7