I have a df like below
> 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
I need to collapse row in a way that output is something like below
> head(df)
OrderId Timestamp1 Timestamp2 ErrorCode Diff
3000000 1455594300434609920 1455594300440175104 0
3000001 1455594300434614272 1455594300440179712 0
3000002 1455594303468741120 1455594303469326848 0
I used df2=aggregate(Timestamp~.,df,FUN=toString)
But output is
OrderId ErrorCode Timestamp
10 3000001 0 1455594300440179712
11 3000002 0 1455594303469326848
12 3000003 0 1455594303713897984
When I dropped the ErrorCode column and used the same command, I get an expected 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
How do I aggregate it in the above manner without removing ErrorCode column. There must be some little thing I am missing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…