【发布时间】:2023-03-24 22:04:02
【问题描述】:
简介: 我在一个无法安装更多软件包的严格环境中工作。我可以从 {stats} 访问 dcast()、xtabs()、reshape()。我无权访问 tydr、reshape 或 reshape2 包。
现在解决问题: 我有一个包含 4 列名称 cust_id、merchant_group、sum 和 max 的汇总数据框,如下所示:
cust_id merchant_group sum max
<int> <chr> <dbl> <dbl>
1 495 AIRLINE 45493 4950
2 495 AUTO RENTAL 3104 1000
3 495 CLOTHING STORES 20928 3140
4 495 DEPARTMENT STORES 1082 495
5 495 DRUG STORES 482 165
我想把它重塑成宽大的形状,看起来像:
cust_id AIRLINE AUTO RENTAL CLOTHING STORES DEPARTMENT STORES DRUG STORES
495 45493 3104 20928 1082 482
495 4950 1000 3140 495 165
我尝试过以下功能:
xtabs(sum~cust_id+merchant_group, data=my.data)
reshape(my.data, idvar = "cust_id", timevar = "merchant_group", direction = "wide")
但不能解决我的问题。提前感谢您的宝贵时间。
【问题讨论】: