Re: [R] rename cols

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Tue 12 Sep 2006 - 12:43:26 GMT

Hi

There is even an Excel like possibility for renaming columns.

try

newDF<-edit(oldDF)

you can go through columns and after clicking on header you can change column name.

Petr

On 12 Sep 2006 at 8:31, hadley wickham wrote:

Date sent:      	Tue, 12 Sep 2006 08:31:43 -0400
From:           	"hadley wickham" <h.wickham@gmail.com>
To:             	"Anupam Tyagi" <AnupTyagi@yahoo.com>
Copies to:      	r-help@stat.math.ethz.ch
Subject:        	Re: [R] rename cols


> > For a newcomer who wants to rename variable "fksm" and "klmk" in a
> > dataframe of with 439 variables there is not easy and intuitive
> > solution. That person has to spend a lot of time listing columns and
> > counting columns or doing string searches or using brackets within
> > brackets within brackets to get a simple thing done. Is there a
> > simple function or solution to this in R without using an add-on
> > package?
>
> I use:
>
> rename <- function(x, replace) {
> replacement <- replace[names(x)]
> names(x)[!is.na(replacement)] <- replacement[!is.na(replacement)]
> x
> }
>
> (which is available in the reshape package)
>
> You use it like:
>
> df <- data.frame(a=1:2, b=3:4)
> df <- rename(df, c(a="variable 1"))
>
> Hadley
>
> ______________________________________________
> 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.

Petr Pikal
petr.pikal@precheza.cz



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 22:46:00 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 Tue 12 Sep 2006 - 13:30:04 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.