簡體   English   中英

R當2列具有不同的值時為data.frame子集

[英]R Subsetting a data.frame when 2 columns have different values

我有一個像這樣的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和Type 2具有不同的值時,我想對其進行子集化。 我的意思是,以一種自動的方式,沒有明確檢查諸如Type1 ==“ DqSAD”&Type2 ==“ rnzDqSAD”這樣的特定值,我記得可以用sql來完成,但是我不知道如何在R中做到這一點。 。

謝謝!

您可以通過使用!=邏輯運算符查找Type1Type2不相等的行來做到這一點。 如果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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM