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

查看:130
本文介绍了比较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)

要测试所有值是否相等:

To test if all values are equal:

all(a == b) # TRUE

b
$ b

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天全站免登陆