[R] Better way to change the name of a column in a dataframe?

Mike Prager mike.prager at noaa.gov
Thu Dec 14 23:05:20 CET 2006


"Ben Fairbank" <BEN at SSANET.COM> wrote:

> [...] I want to correct or otherwise change the name of one of the
> columns, I can do so with 
> 
> > dimnames(frame)[[2]][which(dimnames(frame)[[2]]=="cmlo3")] <- "col3"
> 
> This seems cumbersome and not very intuitive.  How can one accomplish
> this more simply?

This is slightly simpler than what you had:

      names(frame)[which(names(frame) == "cmlo3")] <- "col3"

There are probably better ways still. 

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.



More information about the R-help mailing list