R当两列的值不同时,对data.frame进行子集设置

R当两列的值不同时,对data.frame进行子集设置,r,dataframe,subset,R,Dataframe,Subset,我有这样一个data.frame: Type1 rep1 Type2 rep2 stat p.value 17 DqSAD 1 rnzDqSAD 9 3.7946 0.0101 18 DqSAD 1 DqSAD 10 -0.5278 0.6428 19 DqSAD 1 rnzDqSAD 10 0.4111 0.2231 20 rnzDqSAD 1 DqSA

我有这样一个data.frame:

          Type1 rep1    Type2 rep2    stat p.value
    17    DqSAD    1 rnzDqSAD    9  3.7946  0.0101
    18    DqSAD    1    DqSAD   10 -0.5278  0.6428
    19    DqSAD    1 rnzDqSAD   10  0.4111  0.2231
    20 rnzDqSAD    1    DqSAD    2 -0.3111  0.5085
    21 rnzDqSAD    1 rnzDqSAD    2 -0.8904  0.9080
当Type1和Type2列有不同的值时,我想将其子集。我的意思是以一种自动的方式,不显式地检查这个特定的值,比如Type1==“DqSAD”&Type2==“rnzDqSAD”。我记得这可以用sql完成,但我不知道如何在R中完成


谢谢

您可以通过查找
Type1
Type2
不相等的行来执行此操作=逻辑运算符。如果
df
是数据

> df[with(df, Type1 != Type2), ]
#       Type1 rep1    Type2 rep2    stat p.value
# 17    DqSAD    1 rnzDqSAD    9  3.7946  0.0101
# 19    DqSAD    1 rnzDqSAD   10  0.4111  0.2231
# 20 rnzDqSAD    1    DqSAD    2 -0.3111  0.5085