[英]R Subsetting a data.frame when 2 columns have different values
I have a data.frame like this: 我有一个像这样的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
and I would like to subset it when the columns Type1 & Type 2 have different values. 当列Type1和Type 2具有不同的值时,我想对其进行子集化。 I mean in an automatic way, not explicitly checking for this particular values like Type1=="DqSAD" & Type2=="rnzDqSAD" I remember this could be done with sql, but I don't figure out how to do it in R.
我的意思是,以一种自动的方式,没有明确检查诸如Type1 ==“ DqSAD”&Type2 ==“ rnzDqSAD”这样的特定值,我记得可以用sql来完成,但是我不知道如何在R中做到这一点。 。
Thanks! 谢谢!
You can do this by finding the rows where Type1
and Type2
are not equal with the !=
logical operator. 您可以通过使用
!=
逻辑运算符查找Type1
和Type2
不相等的行来做到这一点。 If df
is the data, 如果
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.