我有一個像下面總結忽略某些列
> head(df)
OrderId Timestamp ErrorCode
1 3000000 1455594300434609920 NA
2 3000001 1455594300434614272 NA
3 3000000 1455594300440175104 0
4 3000001 1455594300440179712 0
5 3000002 1455594303468741120 NA
6 3000002 1455594303469326848 0
我需要一種方式來崩潰行中的DF輸出存在類似下面
> head(df)
OrderId Timestamp1 Timestamp2 ErrorCode Diff
3000000 1455594300434609920 1455594300440175104 0
3000001 1455594300434614272 1455594300440179712 0
3000002 1455594303468741120 1455594303469326848 0
我用df2=aggregate(Timestamp~.,df,FUN=toString)
但輸出
OrderId ErrorCode Timestamp
10 3000001 0 1455594300440179712
11 3000002 0 1455594303469326848
12 3000003 0 1455594303713897984
當我放棄了錯誤代碼列,並使用相同的命令,我得到一個前pected output
> head(kf)
OrderId Timestamp
1 3000000 1455594300434609920
2 3000001 1455594300434614272
3 3000000 1455594300440175104
4 3000001 1455594300440179712
5 3000002 1455594303468741120
6 3000002 1455594303469326848
> kf2=aggregate(Timestamp~.,kf,FUN=toString)
head(kf2)
OrderId Timestamp
10 3000001 1455594300434614272, 1455594300440179712
11 3000002 1455594303468741120, 1455594303469326848
12 3000003 1455594303711330816, 1455594303713897984
如何在不刪除ErrorCode列的情況下以上述方式對其進行聚合。必須有一些我錯過的小東西。
你申請的'ErrorCode'什麼功能? – Sotos
合併到自己然後過濾? 'res < - merge(df1,df1,by =「OrderId」); RES < - 資源[!RES $ Timestamp.x = $資源Timestamp.y,]' – zx8754
Errocode只需要根據的OrderId,NA和0合併爲0 – pythonRcpp