Re: [R] rename cols

From: Tony Plate <tplate_at_acm.org>
Date: Mon 11 Sep 2006 - 17:21:58 GMT

The following works for data frames and matrices (you didn't say which you were working with).

 > x <- data.frame(V1=1:3,V2=4:6)
 > x
   V1 V2
1 1 4
2 2 5

3 3 6
 > colnames(x) <- c("Apple", "Orange")
 > x
   Apple Orange

1     1      4
2     2      5
3     3      6

 >

For a data frame, 'names(x) <- c("Apple", "Orange")' also works, because a dataframe is stored internally as a list of columns.

Ethan Johnsons wrote:
> A quick question please!
>
> How do you rename column names? i.e. V1 --> Apple; V2 --> Orange, etc.
>
> thx much
>
> ej
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



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 Tue Sep 12 03:25:44 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 Wed 13 Sep 2006 - 07:30:05 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.