比较 R 中的两个数据框对象是否相等? [英] Compare if two dataframe objects in R are equal?

查看:32
本文介绍了比较 R 中的两个数据框对象是否相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查两个对象,例如数据帧,R中的值是否相等?

How do I check if two objects, e.g. dataframes, are value equal in R?

值相等,我的意思是一个数据帧的每一列的每一行的值等于第二个数据帧中相应行和列的值.

By value equal, I mean the value of each row of each column of one dataframe is equal to the value of the corresponding row and column in the second dataframe.

推荐答案

目前还不清楚测试两个数据框是否值相等"是什么意思,但是测试值是否相同,这里是一个例子两个具有相同值的不相同的数据帧:

It is not clear what it means to test if two data frames are "value equal" but to test if the values are the same, here is an example of two non-identical dataframes with equal values:

a <- data.frame(x = 1:10)
b <- data.frame(y = 1:10)

测试所有值是否相等:

all(a == b) # TRUE

测试对象是否相同(它们不一样,它们有不同的列名):

To test if objects are identical (they are not, they have different column names):

identical(a,b) # FALSE: class, colnames, rownames must all match.

这篇关于比较 R 中的两个数据框对象是否相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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