[R] rename cols

Doran, Harold HDoran at air.org
Tue Sep 12 14:17:14 CEST 2006

I don't know, this seems pretty simple and intuitive (to me)

# Create a sample data set with 439 variables
tmp <- data.frame(matrix(c(rnorm(4390)), ncol=439))
colnames(tmp)<-paste("col", 1:439, sep = "")

# rename a certain variable in that dataset

Here you are using indexing and a simple evaluation to find a variable
by name in a large data set and rename it. R is so flexible that this
cat can be skinned in many (and maybe even easier) ways, though.


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Anupam Tyagi
> Sent: Tuesday, September 12, 2006 12:34 AM
> To: r-help at 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?
> ______________________________________________
> 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