[R] Individual rename of list items
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Mar 1 12:54:02 CET 2001
> From: "Dieter Menne" <dieter.menne at menne-biomed.de>
> Date: Thu, 1 Mar 2001 12:30:20 +0100
>
> I am confused by the logic of renaming:
>
> # Rename individual list items?
>
> Empl<-list(employee="Anna",spouse="Fred")
> names(Empl)<-c("empl","spo")
> names(Empl)
> #[1] "empl" "spo"
> # worked like a charm... but
>
> names(Empl[1])<-"newempl"
> # no error message, yet ....
> names(Empl)
> #[1] "empl" "spo"
> # where's my newempl???????
>
>
> If this line
>
> names(Empl[1])<-"newempl"
>
> was stupid, why is there no error message?
It wasn't stupid, but it was not what you intended, evidently. Look at
> Empl[1]
$employee
[1] "Anna"
That is a list, and you gave it a new name, making a new copy. You did
not then reference the new copy.
What you intended I think was
names(Empl)[1]<-"newempl"
which works, but seems not allowed in the R documentation ....
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list