我正在处理下面的数据,并希望复制我对R做的Pivot。我能够做总和和最大但不知道如何进行计数。感谢您的帮助
Transaction Location Invoice Paying_Party Charge Delivery Paid Points
123 UK 123_A UK001 1 1 100
123 UK 123_B UK001 1 0 100
123 UK 123_C UK001 1 1 100
124 UK 124_A UK001 1 1 100
124 UK 124_B UK001 0 0 50
125 SE 125_A SE005 0 0 50
126 HK 126_A HK008 1 1 50
126 HK 126_B HK008 1 1 50
127 DE 127_A DE008 1 1 100
128 CN 128_A CN002 0 1 150
128 CN 128_B CN002 0 1 150
128 CN 128_C CN002 0 0 150
128 CN 128_D CN002 0 0 150
129 US 129_A US007 1 1 100
129 US 129_B US007 1 0 100
130 AU 130_A AU111 1 0 150
130 AU 130_B AU111 1 0 150
130 AU 130_C AU111 1 1 150
这是我的代码:
library(data.table)
Summary<-setDT(Report)[, list(Points=max(Points),Charge.Delivery=max(Charge.Delivery),Paid=sum (Paid)),by=list(Transaction,Paying_Party,Location=as.factor(Location))]
由于
答案 0 :(得分:2)
像这样使用Runtime.exec
:
Count = .N
我Summary<-DT[, list(Points = max(Points),
Charge = max(Charge),
Paid = sum (Paid),
Count = .N),
by=list(Transaction,Paying_Party,Location=as.factor(Location))]
DT
和data.table
取代Charge
。