[R] Using a number as a name to access a list
Jan T. Kim
jtk at cmp.uea.ac.uk
Thu Feb 10 16:02:08 CET 2005
On Thu, Feb 10, 2005 at 01:35:56PM -0000, michael watson (IAH-C) wrote:
> I have a variable that contains the following numerical text "04010".
> This is the name to access a list:
>
> > as.list(KEGGPATHID2NAME)$"04010"
> [1] "MAPK signaling pathway"
>
> Marvellous! Except I want to do that when "04010" is assigned to a
> variable called path and I can't figure out how to do it!
>
> > path <- "04010"
> >
> > # the original and best
> > as.list(KEGGPATHID2NAME)$"04010"
> [1] "MAPK signaling pathway"
> >
> > # clearly this doesn't, and shouldn't, work
> > as.list(KEGGPATHID2NAME)$path
> NULL
$ allows only a literal character string or a symbol as the index, according
to the R language definition, but [[ indexing does the same as $ and can
be used for computed indexing. So
as.list(KEGGPATHID2NAME)[[path]]
should do what you want.
Greetinx, Jan
--
+- Jan T. Kim -------------------------------------------------------+
| *NEW* email: jtk at cmp.uea.ac.uk |
| *NEW* WWW: http://www.cmp.uea.ac.uk/people/jtk |
*-----=< hierarchical systems are for files, not for humans >=-----*
More information about the R-help
mailing list