1

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.).

enter image description here

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
asked May 21, 2022 at 11:46

1 Answer 1

1

Please replace

  • subset=! with subset=
  • c1Pos==c1Pos-1 with c2Pos==c1Pos-1
combined_df_locat_short_cues_consec<-subset(combined_df_color_locat_cues, subset=(c2Pos==c1Pos+1|c2Pos==c1Pos-1))
Sign up to request clarification or add additional context in comments.

2 Comments

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
That's right. You are welcome!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.