I have a DF which looks like this (but actually with a lot more data!):
https://i.stack.imgur.com/71RBH.jpg
I am trying to look at every Subject and determine what the "Conditions" were before the "Trigger" switched to 1,2 or 3. Specifically I am trying to create a new DF with information containing three "Condtitions" before the "Trigger" turns to 1,2 or 3.
if(df$Trigger >= 1){
copie 3 rows before trigger (including row with trigger>=1) >= 1 of same Subject and delete rest.
}
The Result should look like this:
https://i.stack.imgur.com/60w4d.jpg
I have been trying to figure this out for weeks but i am too inexperienced. I am grateful for any help.