Home > OS >  Getting subset of data based on conditional values from two columns
Getting subset of data based on conditional values from two columns

Time:05-22

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

CodePudding user response:

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))
  • Related