I want to transform a long and chronological dataset into a wide but chronological dataset by ID Let's see an example:
ID | Product | Date |
---|---|---|
1 | Bike | 1/1/2000 |
1 | Tire | 2/1/2000 |
2 | Car | 15/2/2000 |
2 | Seat | 17/2/2000 |
1 | Chronometer | 20/2/2000 |
Into the following table:
ID | 1st | 2nd | 3rd | etc |
---|---|---|---|---|
1 | Bike | Tire | Chronometer | |
2 | Car | Seat |
The order of the products bought must not be changed.
Can you help me guys?
Thanks a lot!
arrange
the data for eachID
andDate
, give a unique row number for eachID
and cast the data to wide format.data