尝试使用这个函数
all.equal(df[1,],df[2,])
[1] "Attributes: < Component 2: Mean relative difference: 1 >"
通常比较因素可能会产生“意外”的结果……在这种情况下,identity
尝试匹配所有内容,发现不同的 row.names
,你可以从 dput
看到:
> dput(df[1,])
structure(list(x = structure(1L, .Label = c("x", "y"), class = "factor"),
y = structure(2L, .Label = c("x", "y"), class = "factor")), .Names = c("x",
"y"), row.names = 1L, class = "data.frame")
> dput(df[2,])
structure(list(x = structure(1L, .Label = c("x", "y"), class = "factor"),
y = structure(2L, .Label = c("x", "y"), class = "factor")), .Names = c("x",
"y"), row.names = 2L, class = "data.frame")
在这个例子中,简单的
==
就可以使用:
> df[1,]==df[2,]
x y
1 TRUE TRUE
identical
检查“完全相等”。这意味着它也会检查row names
(在此处不同)。 - Arunduplicated
,它用于比较data.frame
的行是否相等。 - Simon O'Hanlon