通过匹配两列的值来过滤数据框 [英] Filtering the dataframe by matching values of two columns
本文介绍了通过匹配两列的值来过滤数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在r中有一个数据框。我想删除两列中的字符串值相等的那些行。我在r中使用了match函数,但无法获得所需的输出。例如,我的数据帧是
I am having a dataframe in r. I want to delete those rows where the values of a string in two columns are equal. I used match function in r but was not able to get desired output. For example my dataframe is
ALDH1A1 ALDH1A1
ITGA7 CHRNA1
PPP1R9A ACTG1
SRGN SRGN
GRB7 ERBB2
PAK1 ERBB2
DLG4 DLG4
PIK3R2 ERBB2
PTPN18 ERBB2
ERBB2 ERBB2
SMURF2 ARHGAP5
NF2 ERBB2
CD82 CD82
ERRFI1 ERBB2
CD44 CD44
TOB1 TOB1
并且在过滤出具有相等列值的行之后,我想要的数据帧是
and my desired data frame after filtering out the rows with equal column values is
ITGA7 CHRNA1
PPP1R9A ACTG1
GRB7 ERBB2
PAK1 ERBB2
PIK3R2 ERBB2
PTPN18 ERBB2
SMURF2 ARHGAP5
NF2 ERBB2
ERRFI1 ERBB2
推荐答案
让我们假设您的数据集称为 dta
Let us imagine your dataset is called dta
然后简单地
dta[which(dta[,1] != dta[,2]), ]
请提供 dput
为了重现您的示例。
Please provide the dput
in order to reproduce your example.
这篇关于通过匹配两列的值来过滤数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文