This question is an extension of R - identify consecutive sequences
I have a data frame in which I need to keep only those trials where in the column ROI I have a consecutive sequence of _aCORRECT1 and _CORRECT1. It doesn't matter how many times _aCORRECT1 and _CORRECT1 occur, they can be repeated.
In the example below, I can keep ntrial 78 and 201, because _aCORRECT1 is followed by _CORRECT1. However, I need to remove the ntrial 10 and 400. In the trial 10 _aCORRECT1 is not followed by _CORRECT1. In the trial 400 _CORRECT1 is not preceded by _aCORRECT1.
Many thanks!
subject ROI ntrial
sbj05 ff 78
sbj05 as 78
sbj05 fgfsd 78
sbj05 sgf 78
sbj05 jh 78
sbj05 sgsgsfg 78
sbj05 fgsfg 78
sbj05 sgf_aCORRECT1 78
sbj05 dfs_CORRECT1 78
sbj05 ffg 78
sbj05 sdfdsf 78
sbj05 sl 78
sbj05 wgrt 78
sbj05 qswefrd 201
sbj05 ssdg 201
sbj05 sdgfdsg 201
sbj05 sgsgd 201
sbj05 sgsdg 201
sbj05 dd_aCORRECT1 201
sbj05 dd_aCORRECT1 201
sbj05 ffds_CORRECT1 201
sbj05 ffds_CORRECT1 201
sbj05 ffds_CORRECT1 201
sbj05 hy 201
sbj05 gfg 201
sbj05 nbc 201
sbj05 cvbvn 10
sbj05 kpj 10
sbj05 nbvnb 10
sbj05 mnm 10
sbj05 dghsfh_aCORRECT1 10
sbj05 gdh 10
sbj05 fgjj 10
sbj05 gnjdg 10
sbj05 gf 10
sbj05 qw 400
sbj05 vfs 400
sbj05 zx 400
sbj05 zvzv 400
sbj05 zvzv_CORRECT1 400
sbj05 zvzd_CORRECT1 400
sbj05 zvv 400
sbj05 cv 400
sbj05 v 400
sbj05 mngy 400