Re: [R] question regarding names() value assignment

Thomas Lumley (thomas@biostat.washington.edu)
Tue, 29 Jun 1999 13:14:32 -0700 (PDT)

Date: Tue, 29 Jun 1999 13:14:32 -0700 (PDT)
From: Thomas Lumley <thomas@biostat.washington.edu>
To: Alex Buerkle <cbuerkle@bio.indiana.edu>
Subject: Re: [R] question regarding names() value assignment
In-Reply-To: <Pine.LNX.4.10.9906291458110.12468-100000@tortoise.bio.indiana.edu>

On Tue, 29 Jun 1999, Alex Buerkle wrote:

>
> I am having trouble assigning a name to single columns in a dataframe.
> The following is an example using 0.64.1 and linux.
>
> tmp is a dataframe.
>
> > names(tmp)
> [1] "some" "thing"
>
> > names(tmp)<-c("else","again")
>
> > names(tmp)
> [1] "else" "again"
>
> > names(tmp[2])
> [1] "again"
>
> > names(tmp[2])<-"altogether"
>
> > names(tmp[2])
> [1] "again"
>
> Can anyone explain this behavior to me?

tmp[2] is a copy of the second column of tmp. You change the name on this
copy, which is then discarded.

You mean

names(tmp)[2]<-"again"

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


This archive was generated by hypermail 1.02.