[R] How to see if row names of a dataframe are stored compactly

From: Hsiu-Khuern Tang <hsiu-khuern.tang_at_hp.com>
Date: Fri 13 Oct 2006 - 23:38:47 GMT

Reading the list of changes for R version 2.4.0, I was happy to see that the row names of dataframes can be stored compactly (as the integer n when row.names(df) is 1:n).

help(row.names) contains this paragraph:

    Row names of the form '1:n' for 'n > 2' are stored internally in a     compact form, which might be seen by calling 'attributes' but never     via 'row.names' or 'attr(x, "row.names")'.

I am unable to get attributes(x)$row.names to return just nrow(x). Am I misreading the documentation? Does "might be seen" mean "possibly in some future version of R" in this case?

> (x <- as.data.frame(matrix(1:9, nrow=3)))
  V1 V2 V3
1 1 4 7
2 2 5 8
3 3 6 9
> attributes(x)$row.names

[1] 1 2 3
> row.names(x) <- seq(len=nrow(x))
> attributes(x)$row.names

[1] 1 2 3


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Oct 14 09:46:20 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 14 Oct 2006 - 07:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.