I have a data.table
with the following form:
date action cnt
1: 2016-06-14 PICK_APPLE 2
2: 2016-06-15 PICK_APPLE 12
3: 2016-06-16 PICK_APPLE 7
4: 2016-06-17 PICK_APPLE 5
5: 2016-08-10 PICK_APPLE 1
6: 2016-08-11 PICK_APPLE 1
7: 2016-08-14 PICK_APPLE 1
8: 2016-08-17 PICK_APPLE 7
9: 2016-08-19 PICK_APPLE 1
10: 2016-08-21 PICK_APPLE 2
11: 2016-08-22 PICK_APPLE 3
12: 2016-08-23 PICK_APPLE 12
13: 2016-08-24 PICK_APPLE 6
14: 2016-08-30 PICK_APPLE 4
15: 2016-08-31 PICK_APPLE 4
16: 2016-09-05 PICK_APPLE 8
17: 2016-09-08 PICK_APPLE 1
18: 2016-08-23 PICK_ORANGE 1
19: 2016-08-31 PICK_ORANGE 2
20: 2016-09-05 PICK_ORANGE 2
21: 2016-08-05 ATE_APPLE 1
22: 2016-08-14 ATE_APPLE 1
23: 2016-08-17 ATE_APPLE 1
24: 2016-08-18 ATE_APPLE 1
25: 2016-08-30 ATE_APPLE 3
date action cnt
And I want to create a table with the column names as the unique values from the action
column and the row names as the unique values within the date
column. E.g the result should be something like:
date PICK_APPLE PICK_ORANGE ATE_APPLE
1: 2016-06-14 2
2: 2016-06-15 12
3: 2016-06-16 7
4: 2016-06-17 5
21: 2016-08-05 1
5: 2016-08-10 1
6: 2016-08-11 1
7: 2016-08-14 1 1
8: 2016-08-17 7 1
24: 2016-08-18 1
9: 2016-08-19 1
10: 2016-08-21 2
11: 2016-08-22 3
12: 2016-08-23 12 1
13: 2016-08-24 6
14: 2016-08-30 4
15: 2016-08-31 4 2
16: 2016-09-05 8
17: 2016-09-08 1
20: 2016-09-05 2
date PICK_APPLE PICK_ORANGE ATE_APPLE
Is there a standard way of doing this, or will I need to do this by looping through each of the (date,action)
combinations?