Re: [R] behavior of names

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 06 Dec 2005 - 15:37:10 EST

You want the individual elements, not a subvector, thus you need to use [[ rather than [:

c(d = x[["a"]], e = x[["b"]])

Compare:

str(x[["a"]])

and

str(x["a"])

On 12/5/05, Ben Bolker <bolker@zoo.ufl.edu> 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?
>
> sincerely
> Ben Bolker
>
> ______________________________________________
> 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
>



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 15:44:38 2005

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