[Rd] row names and identical

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jul 14 22:11:10 CEST 2007


Below x1, x2 and x3 all have the same data and all have the same value
for row.names(x); however, the internal values of their row.names differ.
The internal value of row.names is c(NA, -4L) for x1, c(NA, 4L) for x2 and
c("1", "2", "3", "4") for x3; nevertheless, identical regards x1 and x2 as
identical while x3 is not identical to either of x1 or x2.

Is this intended?
Desirable?
Why do we need different internal representations for row.names
for x1 and x2?


> x1 <- x2 <- x3 <- data.frame(x = 11:14)
> row.names(x2) <- 1:4
> row.names(x3) <- as.character(1:4)
>
> # they all have the same value for row.names()
> row.names(x1)
[1] "1" "2" "3" "4"
> row.names(x2)
[1] "1" "2" "3" "4"
> row.names(x3)
[1] "1" "2" "3" "4"
>
> # but internally they are all different
> dput(x1)
structure(list(x = 11:14), .Names = "x", row.names = c(NA, -4L
), class = "data.frame")
> dput(x2)
structure(list(x = 11:14), .Names = "x", row.names = c(NA, 4L
), class = "data.frame")
> dput(x3)
structure(list(x = 11:14), .Names = "x", row.names = c("1", "2",
"3", "4"), class = "data.frame")
>
> # identical regards x1 and x2 as the same while x3 differs
> identical(x1, x2)
[1] TRUE
> identical(x1, x3)
[1] FALSE
> identical(x2, x3)
[1] FALSE
>
> R.version.string # XP
[1] "R version 2.5.1 (2007-06-27)"



More information about the R-devel mailing list