Re: [R] behavior of names

From: Patrick Connolly <p.connolly_at_hortresearch.co.nz>
Date: Tue 06 Dec 2005 - 16:22:04 EST

On Tue, 06-Dec-2005 at 04:14AM +0000, Ben Bolker wrote:

|>
|> I find the following ways in which
|> R attempts to preserve names to
|> be puzzling and often annoying
|>
|> x = c(a=1,b=2,c=3)
|> c(d=x["a"],e=x["b"])
|>
|> # d.a e.b
|> # 1 2
|> list(d=x["a"],e=x["b"])
|>
|> # $d
|> # a
|> # 1
|>
|> # $e
|> # b
|> # 2
|>
|> (a real-world example: I fit
|> some parameters with mle(), ending
|> up with a named vector of coefficients,
|> and then want to use some or all of
|> those coefficients as input to another
|> mle() call -- I have to remove the
|> names manually.)
|>
|> Can anyone suggest why this happens/
|> why it is a good design/whether there
|> are simple workarounds?

Makes perfect sense to me. It's good to know where elements of lists came from.

For dealing with the vector, you could do this:  xv <- c(x["a"],x["b"])
names(xv) <- c("d", "e")

Not so simple with the list

list(d=as.vector(x["a"]),e=as.vector(x["b"]))

HTH

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Dec 06 16:30:01 2005

This archive was generated by hypermail 2.1.8 : Tue 06 Dec 2005 - 17:25:33 EST