Re: [R] Column renaming

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Mon, 05 May 2008 19:33:37 +0200

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

______________________________________________
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.
Received on Mon 05 May 2008 - 17:46:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 05 May 2008 - 19:30:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive