I have a problem in data wrangling in R. So I have a data frame like this:
CardID Date Amount ItemNumber ItemCode
1 C0100000111 2001-07-19 449.00 1 I0000000808
2 C0100000111 2001-02-20 9.99 1 I0000000622
3 C0100000111 2001-04-27 49.99 1 I0000000284
4 C0100000111 2001-02-20 69.00 1 I0000000488
5 C0100000111 2001-05-17 299.00 1 I0000000595
6 C0100000111 2001-05-19 5.99 1 I0000000078
7 C0100000199 2001-08-20 229.00 1 I0000000783
8 C0100000199 2001-12-29 229.00 1 I0000000783
9 C0100000199 2001-06-28 139.00 1 I0000000537
10 C0100000343 2001-09-07 99.00 1 I0000000532
I want to convert it in a structure like this,
CardID, FirstPurchaseDate, LastPurchaseDate, NumberOrders, NumberSKUs, TotalAmounts
Where each row of CardID in the new table is unique. How can I make this possible?
Based on the table above, I expected an output like this
> Ex
CardID FirstPurchaseDate LastPurchaseDate NumberOrders NumberSKUs TotalAmounts
1 C0100000111 2001-02-20 2001-07-19 6 6 882.97
2 C0100000199 2001-06-28 2001-12-29 3 2 597.00
3 C0100000343 2001-09-07 2001-09-07 1 1 99.00