I have a data set similar to the following:
ID Parent_ID Outcome
1a Black
2a Green
3a 1a Red
4a Blue
5a 2a Yellow
6a 5a Orange
7a Teal
8a Purple
9a 3a Brown
with Parent_IDs
linked to a previous event, and which also have their own IDs generated each time an event occurs. What I'd like to do is group together related events in the form of subsequent rows, or by creating one data frame with multiple columns that link each event.
Output re: option 1 (rows):
ID Parent_ID Outcome
1a Black
3a 1a Red
9a 3a Brown
2a Green
5a 2a Yellow
6a 5a Orange
4a Blue
7a Teal
8a Purple
Output re: option 2 (data frame):
ID Parent_ID Outcome 1 ID_2 Outcome 2 ID_3 Outcome_3
1a Black 3a Red 9a Brown
2a Green 5a Yellow 6a Orange
4a Blue NA NA NA NA
7a Teal NA NA NA NA
8a Purple NA NA NA NA
I've tried sub-setting blank Parent_ID
, creating a new data frame and binding the resulting rows but I don't think this would solve my issue beyond 2 instances of an event. My issue is handling the fact that there could be (potentially) an infinite number of related events. Does anyone have any suggestions? Thank you for your time.