r - 确定 `identical()` 返回 FALSE 的原因

标签 r dataframe

我有两个 data.frames,我希望它们是相同的,但 same() 返回 false。

作为背景,一个 DF 来自 Iris 数据 ARFF 文件,而另一个来自 .rdata 文件,如果它改变了什么

x == y 中的所有元素都为 TRUE,两个变量的类相同,两个变量的行名相同,列名也相同。

如何确定触发 FALSE 输出的原因?

编辑: all.equal 的输出如下所述

[1] "Component 1: Attributes: < Modes: list, NULL >"                                
[2] "Component 1: Attributes: < names for target but not for current >"             
[3] "Component 1: Attributes: < Length mismatch: comparison on first 0 components >"

编辑:两者属性的输出
> attributes(dataset)
$names
[1] "Class"        "petal-length" "petal-width"  "sepal-length" "sepal-width" 
$row.names
[1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32
[33]  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64
[65]  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96
[97]  97  98  99 100
$class
[1] "data.frame"

> attributes(dataset2)
$names
[1] "Class"        "petal-length" "petal-width"  "sepal-length" "sepal-width" 
$row.names
[1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32
[33]  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64
[65]  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96
[97]  97  98  99 100
$class    
[1] "data.frame"
`

str(x) 的输出:
> str(dataset)
'data.frame':   100 obs. of  5 variables:
$ Class       : atomic  1 0 1 0 1 0 0 0 1 1 ...
..- attr(*, "feature.type")= chr "Numeric"
$ petal-length: atomic  6.3 4.8 7.2 5.2 6.7 4.9 5.5 5.3 6.4 6.1 ...
..- attr(*, "feature.type")= chr "Numeric"
$ petal-width : atomic  2.9 3.4 3.2 3.4 3.1 3.6 3.5 3.7 3.1 2.6 ...
..- attr(*, "feature.type")= chr "Numeric"
$ sepal-length: atomic  5.6 1.6 6 1.4 5.6 1.4 1.3 1.5 5.5 5.6 ...
..- attr(*, "feature.type")= chr "Numeric"
$ sepal-width : atomic  1.8 0.2 1.8 0.2 2.4 0.1 0.2 0.2 1.8 1.4 ...
..- attr(*, "feature.type")= chr "Numeric"
> str(dataset2)
'data.frame':   100 obs. of  5 variables:
$ Class       : num  1 0 1 0 1 0 0 0 1 1 ...
$ petal-length: num  6.3 4.8 7.2 5.2 6.7 4.9 5.5 5.3 6.4 6.1 ...
$ petal-width : num  2.9 3.4 3.2 3.4 3.1 3.6 3.5 3.7 3.1 2.6 ...
$ sepal-length: num  5.6 1.6 6 1.4 5.6 1.4 1.3 1.5 5.5 5.6 ...
$ sepal-width : num  1.8 0.2 1.8 0.2 2.4 0.1 0.2 0.2 1.8 1.4 ...
> 

最佳答案

尝试类似:

all.equal(x,y)

否则看library(compare) .

关于r - 确定 `identical()` 返回 FALSE 的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20575471/

相关文章:

python - Pandas DataFrame 中列的值列表

r - 如何在函数调用中将 `list2env()`(或通过管道传输到 `assign()`)?

python - 如果坐标对不在列表中,则从数据框中删除

r - 如果满足多个条件,则将值从一个数据帧复制到另一个数据帧 (R)

r - 在 R 和 gnuplot 中绘制大量 x、y、z 点进行 3D 绘图,并在每个时间步提取 bmp/gif/png 文件

python - 按特定列对行(组内)的 Pandas df 子集进行排序

java - 使用 Spark/Java 获取每行数据帧的当前时间戳

r - R中逻辑向量中连续值的相交范围

r - 使用 grid.arrange 底部的通用 x 轴标签和图例

r - 根据列的子字符串创建行