[R] Column renaming

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon May 5 19:33:37 CEST 2008


Duncan Murdoch wrote:
> 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
>
...or, essentially the same:

X <- within(X, {sue <-bob; rm(bob)})

Manipulating the names attribute should  be  more efficient, although 
not by order of magnitudes, I think.



-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list