[R] Column renaming

Duncan Murdoch murdoch at stats.uwo.ca
Mon May 5 19:01:47 CEST 2008


On 5/5/2008 10:48 AM, Chip Barnaby wrote:
> Dear all,
> 
> Is there a less cumbersome way to rename a column by name (as opposed 
> to index) than --
> 
> names( X)[ names[ X] == "bob"]<-"sue"

I find this clearer:

X$sue <- X$bob
X$bob <- NULL

Duncan Murdoch

> 
> ?
> 
> A semi-related question: how does one get the index of a column by 
> name, something along the lines of col.index( X, "sue") ?
> 
> 
> Chip Barnaby
> 
> 
> ---------------------------------------------------------
> Chip Barnaby                   cbarnaby at wrightsoft.com
> Vice President of Research
> Wrightsoft Corp.               781-862-8719 x118 voice
> 131 Hartwell Ave               781-861-2058 fax
> Lexington, MA 02421         www.wrightsoft.com
> 
> ______________________________________________
> R-help at r-project.org 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