On Thu, 20 Jan 2011, Nick Sabbe wrote:

Hello list.

Another 'puzzle' for which I don't have a clean solution.
Say I have a multidimensional object, e.g.:
Mm<-matrix(1:6, nrow=2, dimnames=list(c("a","b"), c("g","h","i")))
And on the other hand I have a list
Ind<-list("b","g")
This holds, for each dimension, an indexer for that dimension.
Now I would like to get the element pointed at by the list.
The obvious solutions don't seem to work, and I can't seem to get do.call to
call the indexer ('[') on my multidimensional object.

Any suggestions?

do.call(`[`, c(quote(Mm), Ind))
[1] 2
do.call(`[`, c(list(Mm), Ind))
[1] 2

gives

Mm["b", "g"]
[1] 2

The first refers to the object by name, the second uses it directly.


Thanks in advance,

Nick Sabbe
--
ping: nick.sa...@ugent.be
link: http://biomath.ugent.be

--
Brian D. Ripley,                  rip...@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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to