[R] rename cols

Tony Plate tplate at acm.org
Mon Sep 11 19:21:58 CEST 2006


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.

-- Tony Plate

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 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