I want to get rid of repeated measures in my data file. The idea is that people pressed the space bar and I want to eliminate rows when participants pressed the key more frequently than once in 3 seconds. I created this loop, but I see that it doesn't remove all the cases and it throws an error because the number of rows changes all the time.
Do you have an idea, of how to change this loop to make it serve its purpose correctly?
df_window_rem <- df_window
for (i in 2:nrow(df_window_rem)) {
p <- df_window_rem[[i,3]] ##cell with time people presses
q <- df_window_rem[[i-1,3]] ##cell with the previous click
x <- df_window_rem[[i,4]] ##score 0/1 for this cell
y <- df_window_rem[[i-1,4]] ##score 0/1 for previous cell
if((p-q)<3){
if (x == 1 & y == 0) {
df_window_rem <- df_window_rem[-(i-1)]
} else if (x == 0 & y == 1){
df_window_rem <- df_window_rem[-i]
} else if (x == 1 & y == 1) {
df_window_rem<- df_window_rem[-i]
}
}
}