检查R中数据框中的相同列 [英] Checking for identical columns in a data frame in R

查看:51
本文介绍了检查R中数据框中的相同列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个名为data的数据框,具有两个相同的列:

Suppose you have a data frame called data with two identical columns:

A B
1 1
2 2
3 3
4 4

如何检查这些两列相同,并返回一个逻辑值来表示吗?一个非常基本的伪代码是:

How can I check if these two columns are identical and return one logical value to indicate it? A very basic pseudocode is:

if(data$A == data$B)
{
   print("Column A and B are identical")
}

我一直在搞乱这样做有一点,并且还没有找到一种似乎并不必要地令人费解的方法。谢谢。

I have been messing around with this for a bit and haven't found a way to do it that doesn't seem unnecessarily convoluted. Thanks.

推荐答案

您可以使用相同

identical(DT[['A']],DT[['B']])

这篇关于检查R中数据框中的相同列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆