Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

Re: [R] rename cols

Tony Plate

2006-09-11

Replies:

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@(protected)
> 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@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.