gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:09:26 26 4
gpt4 key购买 nike

我有两个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com