检查 R 中一个数据帧中的两列是否具有相同的值 [除了 NA 之外]
我有 1 个数据帧,j:
Chr|Pos|A0|A1|rsID|Beta-A1|P|info|maf|se|rsid
1|16021|C|T|NA|0.410|0.26|0.842|0.01|NA|rs1163602158
1|17483|C|T|rs845637483|-0.356|0.32|0.856|0.01|NA|rs845637483
1|19250|T|C|NA|-0.255|0.54|0.812|0.01|NA|rs7465843777
1|39402|T|TCAA|NA|-0.873|0.37|0.821|0.01|NA|rs2746475333
1|39883|G|C|NA|0.195|0.59|0.808|0.01|NA|rs2726463882
我想检查 rsID 和 rsid 中的行是否与前一列中的 NA 相同
所以我可以做
table(ifelse(j$rsID==j$rsid,"Yes","No"))
No Yes
701232 18207968
而且我可以做
table(is.na(j$rsID))
FALSE TRUE
18909200 2550533
table(is.na(j$rsid))
FALSE
21459733
所以我可以看到那里有 701232 个不匹配的实例,但这些并不是全部,因为 NA,因为 NA 的数量比不匹配的实例多(2550533)?
有没有更好/更干净的方法来做到这一点,以便我可以更好地了解这一点?
谢谢
I have 1 dataframe, j:
Chr|Pos|A0|A1|rsID|Beta-A1|P|info|maf|se|rsid
1|16021|C|T|NA|0.410|0.26|0.842|0.01|NA|rs1163602158
1|17483|C|T|rs845637483|-0.356|0.32|0.856|0.01|NA|rs845637483
1|19250|T|C|NA|-0.255|0.54|0.812|0.01|NA|rs7465843777
1|39402|T|TCAA|NA|-0.873|0.37|0.821|0.01|NA|rs2746475333
1|39883|G|C|NA|0.195|0.59|0.808|0.01|NA|rs2726463882
I want to check whether the rows in rsID and rsid are the same ASIDE from the NAs in the former column
So I can do
table(ifelse(j$rsID==j$rsid,"Yes","No"))
No Yes
701232 18207968
And I can do
table(is.na(j$rsID))
FALSE TRUE
18909200 2550533
table(is.na(j$rsid))
FALSE
21459733
So I can see that there are 701232 instances where they don't match, but these are not ALL because of NA because there are MORE (2550533) NA than instances of them not matching?
Is there a better / cleaner way of doing this, so I can get a better idea of this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可以删除Na,然后过滤它们不相等的地方:
Could remove NA then filter where they are not equal:
另一个 dplyr 选项
输出
Another dplyr option
Output
我们可以使用
基础R
We can use
base R