问题
I have a data.frame like this:
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. 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.
Thanks!
回答1:
You can do this by finding the rows where Type1
and Type2
are not equal with the !=
logical operator. If df
is the data,
> 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
来源:https://stackoverflow.com/questions/25826743/r-subsetting-a-data-frame-when-2-columns-have-different-values