[R] How to see if row names of a dataframe are stored compactly
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Oct 14 01:59:27 CEST 2006
Try this:
> class(attributes(x)$row.names)
[1] "integer"
> rownames(x) <- as.character(rownames(x))
> class(attributes(x)$row.names)
[1] "character"
On 10/13/06, Hsiu-Khuern Tang <hsiu-khuern.tang at hp.com> wrote:
> 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
>
> Best,
> Hsiu-Khuern.
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list