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"
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
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
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
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
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
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
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
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
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
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
--
11 matches
Mail list logo