I have a df called data_clean:
> head(data_clean)
participant type target_onset key_resp.rt central_size
1 1010 gap 0.4 0.3260000 0.15
2 1010 gap 0.1 0.3380001 0.15
3 1010 overlap 0 0.4480000 0.10
4 1010 gap 0.2 0.3940001 0.10
5 1010 gap 0.1 0.3980000 0.10
6 1010 gap 0.2 0.4990001 0.10
I would like to add a column called trial_num that +=1 every row until the participant column number changes. And then it should start again. So if the next participant started after 6 trials, it would look something like this:
participant type target_onset key_resp.rt central_size trial_num
1 1010 gap 0.4 0.3260000 0.15 1
2 1010 gap 0.1 0.3380001 0.15 2
3 1010 overlap 0 0.4480000 0.10 3
4 1010 gap 0.2 0.3940001 0.10 4
5 1010 gap 0.1 0.3980000 0.10 5
6 1010 gap 0.2 0.4990001 0.10 6
7 1011 gap 0.4 0.3260000 0.15 1
8 1011 gap 0.1 0.3380001 0.15 2
9 1011 overlap 0 0.4480000 0.10 3
Any suggestions are much appreciated. Thanks.