Here is the data:
marker <- c(0,0,0,0,3,3,0,0,5,5,5,0,0,0,
1,1,2,2,2,2,0,0,1,1,1,3,3,3,
1,1,2,2,2,0,0,1,1,1,5,5,5,5)
Those markers show what the participant was doing during an eye tracking study, such that 0 = no trial, 1 = trial onset, 2, 3, 5 = different types of tasks. The data before the first 1 is eye tracker test and can be discarded.
What I need to do (preferably with dplyr
):
- Delete data before the first 1
- Calculate the length of each sequence of repeating numbers (
n_samples
) - Assign ID numbers to trials and 0's to no trial and trial onset (
trial_number
)
Desired output:
marker n_samples trial_number
1 2 0
1 2 0
2 4 1
2 4 1
2 4 1
2 4 1
0 2 0
0 2 0
1 3 0
1 3 0
1 3 0
3 3 2
3 3 2
3 3 2
1 2 0
1 2 0
2 3 3
2 3 3
2 3 3
0 2 0
0 2 0
1 3 0
1 3 0
1 3 0
5 4 4
5 4 4
5 4 4
5 4 4
I found this answer, but wasn't able to modify the code to fit my task.
Thank you!