确定`same()`返回FALSE的原因

时间:2013-12-13 20:30:58

标签: r dataframe

我有两个数据框架,我期望是相同的,但是same()返回false。

作为背景,一个DF来自Iris数据ARFF文件,而另一个DF来自.rdata文件,如果它改变任何东西

x == y中的所有元素都为TRUE,两个变量的类相同,两者的rownames相同,colnames也是如此。

如何确定触发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 ...
> 

2 个答案:

答案 0 :(得分:2)

尝试类似:

all.equal(x,y)

否则请查看library(compare)

答案 1 :(得分:1)

如果您想知道不同的那个,可以使用

which(x != y, arr.ind=TRUE)