I have two data.frames that I expect to be the same, but identical() returns false.
As a background, one DF comes from the Iris data ARFF file, while the other a .rdata file, if that changes anything
All the elements in x == y are TRUE, the class is the same for both variables, the rownames are the same for both, as are the colnames.
How do I determine what triggered the FALSE output?
EDIT: output of all.equal as stated below
[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 >"
EDIT: output of attributes of both
> 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"
`
output from 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 ...
>
Try something like:
all.equal(x,y)
Otherwise look at library(compare)
.
If you want to know the one that's different, you can use
which(x != y, arr.ind=TRUE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With