简体   繁体   中英

Getting subset of data based on conditional values from two columns

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 (eg, 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM