I'm searching for a way to aggregate rows, based on date and ID, but arranging the values depending on one of te colums' values.
Basically I want to convert this:
DATE ID V1 V2 SHIFT
1 2020-05-21 A 21 34 morning
2 2020-05-21 A 6 12 afternoon
3 2020-05-20 A 19 15 morning
4 2020-05-20 A 7 16 afternoon
5 2020-05-20 B 17 20 morning
6 2020-05-20 B 5 11 afternoon
Into this:
DATE ID V1_mor V2_mor V1_aft V2_aft
1 2020-05-21 A 21 34 6 12
2 2020-05-20 A 19 15 7 16
3 2020-05-20 B 17 20 5 11
I've tried the route of making a loop and adding a bunch of "if" statements, but I don't want to get caught in bad practice.
The goal is so I can later add another column with a calculation of the style of (v1_mor * v2_aft) / v2_mor