I am working with eye-tracking data and I am trying to create a new column 'SaccadePerTrial' which will count (and label) the occurrence of saccades (S) within each unique trial (while ignoring fixations (F)).
This is how my dataframe looks like currently:
Trial | FixationSaccade
1 | F
1 | F
1 | S
1 | S
1 | F
1 | F
1 | S
1 | S
2 | F
2 | F
2 | S
2 | S
2 | F
2 | F
2 | S
2 | S
And this is how the 'SaccadePerTrial' column should look like:
Trial | FixationSaccade | SaccadePerTrial
1 | F | NA
1 | F | NA
1 | S | 1
1 | S | 1
1 | F | NA
1 | F | NA
1 | S | 2
1 | S | 2
2 | F | NA
2 | F | NA
2 | S | 1
2 | S | 1
2 | F | NA
2 | F | NA
2 | S | 2
2 | S | 2
This is similar to the function rleid(), but I would like the function to ignore values that are not saccades (S). An alternative option (although the less preferred one) would be to rleid() each value in the 'FixationSaccade' column separately (having both the Fs and Ss start from 1).
Does anyone have an idea how I can achieve this? Thank you!