On Mon, May 5, 2008 at 12:08 PM, hadley wickham <[EMAIL PROTECTED]> wrote:
> On Mon, May 5, 2008 at 10:54 AM, Chip Barnaby <[EMAIL PROTECTED]> wrote:
> > Yes, someone else pointed out my typo, sorry.
> >
> > My issue here is that referring to columns by index is risky. Hard-coded
> > indices will be buried in code and there will be trouble if (when) the data
> > organization changes. So I am trying to learn how to work with names, but
> > the language does not seem to allow that approach without some awkwardness.
> > I guess I could write some helper functions.
>
> There's the rename function in the reshape package:
>
> library(reshape)
> X <- rename(X, c("bob" = "sue")
Or if you just want the function:
rename <- function (x, replace) {
replacement <- replace[names(x)]
names(x)[!is.na(replacement)] <- replacement[!is.na(replacement)]
x
}
Hadley
--
http://had.co.nz/
______________________________________________
[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.