Re: [R] obtaining the name of a named list

About this list Date view Thread view Subject view Author view Attachment view

From: Uwe Ligges (ligges@statistik.uni-dortmund.de)
Date: Mon 17 May 2004 - 00:03:33 EST


Message-id: <40A774B5.4020601@statistik.uni-dortmund.de>

Ned wrote:

> I have a list d, in which the names of each elements are single
> characters, and the actual elements are bit sequences representing those
> characters. If I type d[1], I get the name and the bit sequence. If I
> type d[[1]], I get only the bit sequence.

d[1] returns a list of length 1, while d[[1]] returns only the element.

> What I want is some way to be able to get the name of the element,
> preferably by specifying an index into the array.
>
> e.g.
>
> > d
> A B C
> "00000" "00001" "0001"
>
> I want some way of saying "give me the name for element number 2" and it
> should return B.

names(B)[2]

Uwe Ligges

BTW: If all list elements are character of length 1, why are you not
using a character vector instead?

>
> cheers,
>
> Ned
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.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://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:11 EST