Subject ID Condition Task A Task B First Task
1001 1
1002 2
1003 1
This is a within-subjects design. Each participant took part in tasks A and B, however, the order in which the tasks were presented (first or second) depends upon condition (e.g., those in condition 1 perform task A first followed by task B and vice-versa). Note that the task columns do have their own score but I cannot add here.
Is it possible to produce an elegant piece of code that mutates a new column/variable called 'first task' that selects cases when a subject belonging to condition 1, their corresponding score from task A is put into this new 'first task' column. Those subjects belonging to condition 2, their score from task B is put into the first task column (because those in condition 2 received task B first).
I hope this makes sense. I am trying to combine mutate with cases_when, group_by and if/if_else functions to achieve something like this, but have not succeeded.