【发布时间】:2018-12-27 07:39:36
【问题描述】:
我的情况如下:有一个数据框列表
类(cc.purc$items)=>“列表”
长度(cc.purc$items)=> 970
class(cc.purc$items[[1]]) => "data.frame"
head(cc.purc$items, 2)
[[1]]
barcode quantity price amount grams litres
1 abc 1 1.00 1.00 NA NA
2 xyz 1 1.29 1.29 NA NA
[[2]]
barcode quantity price amount grams litres
1 abc2 1 5.5 5.5 NA NA
2 xyz2 -1 19.5 -19.5 NA NA
cc.purc 为“items”列表中的每个数据帧都有一个名为“transaction_id”的字段。
head(cc.purc$transaction_id, 2) => "62740" "62741"
我想打印列表中包含的所有数据帧中的所有行,并将相应的 transaction_id 作为附加列添加到所有行。
例如:想要关注
barcode quantity price amount grams litres tran_id
1 abc 1 1.00 1.00 NA NA 62740
2 xyz 1 1.29 1.29 NA NA 62740
3 abc2 1 5.5 5.5 NA NA 62741
4 xyz2 -1 19.5 -19.5 NA NA 62741
如何做到这一点?请帮忙。
要从列表“项目”中的所有 DF 中获取所有行,我可以执行以下操作:
do.call("rbind", cc.purc$items)
但是如何将对应的列(transaction_id)添加到所有相关行是我无法弄清楚的?
【问题讨论】: