Re: [R] Column renaming

2008-05-05 Thread Gabor Grothendieck
There is a rename function in the reshape package and also one in the memisc package. On Mon, May 5, 2008 at 10:48 AM, Chip Barnaby <[EMAIL PROTECTED]> 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"

Re: [R] Column renaming

2008-05-05 Thread Peter Dalgaard
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 <- wi

Re: [R] Column renaming

2008-05-05 Thread hadley wickham
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 change

Re: [R] Column renaming

2008-05-05 Thread hadley wickham
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

Re: [R] Column renaming

2008-05-05 Thread Erik Iverson
I agree there. I believe the same effect can be achieved with 'transform'. transform(X, sue = bob, bob = NULL) Perhaps there are performance reasons for using the names() <- value approach for very large data.frames? Duncan Murdoch wrote: On 5/5/2008 10:48 AM, Chip Barnaby wrote: Dear all

Re: [R] Column renaming

2008-05-05 Thread Duncan Murdoch
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 ge

Re: [R] Column renaming

2008-05-05 Thread Chip Barnaby
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

Re: [R] Column renaming

2008-05-05 Thread Peter Dalgaard
Chip Barnaby wrote: > Peter, > My method seems to work, see below. Is there some reason it might not > work in general? This is the tersest way I have found to rename, but > it seems awkward, given that names( X) is repeated. > Nono, this technique works fine. It just wasn't what you wrote (l

Re: [R] Column renaming

2008-05-05 Thread Chip Barnaby
Peter, My method seems to work, see below. Is there some reason it might not work in general? This is the tersest way I have found to rename, but it seems awkward, given that names( X) is repeated. Chip Barnaby -- > head( airquality) Ozone Solar.R Wind Temp Month

Re: [R] Column renaming

2008-05-05 Thread Peter Dalgaard
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" > > ? Not that I know of (notwithstanding that your code doesn't quite work as it stands...). You might have thought that this woul

[R] Column renaming

2008-05-05 Thread Chip Barnaby
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" ? 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 --