I have a data frame called (image attached below) where I need to select rows based on conditional values of two columns. Specifically, I need to select those rows where c1Pos and c2Pos have consecutive values (e.g., 4 and 5, 3 and 2, etc.).
I have tried the following, but it doesn't work:
combined_df_locat_short_cues_consec<-subset(combined_df_color_locat_cues, subset=!(c2Pos==c1Pos+1|c1Pos==c1Pos-1))
Any help would be very much appreciated.
Thanks in advance,
Mikel
Phil
8,1973 gold badges42 silver badges76 bronze badges
1 Answer 1
Please replace
subset=!withsubset=c1Pos==c1Pos-1withc2Pos==c1Pos-1
combined_df_locat_short_cues_consec<-subset(combined_df_color_locat_cues, subset=(c2Pos==c1Pos+1|c2Pos==c1Pos-1))
answered May 21, 2022 at 20:35
Nobukuni Hyakutake
866 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Mikel Jimenez
Hi Nobukuni, that worked great! On the other hand, I'm trying to do the inverse also, that's it all the trials where c1Pos and c2Pos are not consecutive. In that case, I'd use "subset=!(c2Pos==c1Pos+1|c2Pos==c1Pos-1)), right? Thanks in advance
Nobukuni Hyakutake
That's right. You are welcome!
lang-r