[R] Using a list as multidimensional indexer

Nick Sabbe nick.sabbe at ugent.be
Thu Jan 20 11:27:09 CET 2011


Hm. I got somewhat further:

Ind2<-list(Mm,"b","g")
do.call("[",Ind2)
Seems to work.

However, now I need it one step beyond: in fact, my actual multidimensional
object holds one dimension more than my list holds indexes.
i.e.: I want the equivalent of Mm["a",].

I tried some variants of
Ind3<-list(Mm,"b",NULL)
do.call("[", Ind3)
But all of these return integer(0).

So the actual new question is: how do I pass a 'missing' argument through a
do.call?

Thanks for any pointers,


Nick Sabbe
--
ping: nick.sabbe at ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove




-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Nick Sabbe
Sent: donderdag 20 januari 2011 11:05
To: r-help at r-project.org
Subject: [R] Using a list as multidimensional indexer

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?

Thanks in advance,

Nick Sabbe
--
ping: nick.sabbe at ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove

______________________________________________
R-help at 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.



More information about the R-help mailing list