> 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

______________________________________________
[email protected] 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.

Reply via email to