Re: [Rd] R-devel: rownames of a data.frame

From: Martin Maechler <maechler_at_r-project.org>
Date: Tue 05 Dec 2006 - 17:20:12 GMT

Gregor Gorjanc <gregor.gorjanc <at> bfro.uni-lj.si> writes:

>
> Hello!
>
> Data.frames have new rownames funcionality, however in use of colnames<-
> in R-devel "changes" this. Here is the example:
>
> > df1 <- data.frame(letters[1:5])
> > attributes(df1)
> $names
> [1] "letters.1.5."
>
> $row.names
> [1] 1 2 3 4 5
>
> $class
> [1] "data.frame"
>
> > colnames(df1) <- "bla"
> > attributes(df1)
> $names
> [1] "bla"
>
> $row.names
> [1] "1" "2" "3" "4" "5"
>
> $class
> [1] "data.frame"
>
> ?rownames/colnames help page (R-devel) says that value is coerced to
> character, but why are rownames coerced to character if I assign
> colnames to a data.frame?
>

because colnames() and rownames() work via dimnames(), and so do  "colnames<-" and "rownames<-" ---
I think it would be unwise to change this, since it's well documented property of these functions.

As you noted yourself, using names() and "names<-" i.e.,
  names(df1) <- "bla"
in the example above, is the recommended way for data frames and does not change the rownames to character.



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Dec 06 15:50:27 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 Thu 07 Dec 2006 - 09:30:55 GMT.

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