There appear to be two independent ways of solving it:
(1) matrix indexing, as in b[rbind(c(1,3,2,1)[permutation])]
(2) do.call(), as in
ind <- as.list(c(1,3,2,1)[permutation]) do.call("[", c(list(b), ind))
I found both these very instructive (us ex-matlab users often overlook matrix indexing!) but to me the
do.call() solution is positively sublime (Peter, why didn't you like it? let's get an aesthetics discussion going!)
I spent some considerable time over lunch today reading the helppages for do.call(), "[", and c().
There is no way under the Sun that I would have come up with the second command above.
Could we add this example or one like it to help(do.call)?
Also, the help page for "[" doesn't include what do.call() did, namely
"["(b,1,3,1,2)
could we add this or some similar example to ?"[" please?
cheers
rksh
>a <- 1:24 dim(a) <- c(2,3,2,2) permutation <- c(1,2,4,3) b <- aperm(a,permutation)> >
-- Robin Hankin Uncertainty Analyst Southampton Oceanography Centre SO14 3ZH tel +44(0)23-8059-7743 [EMAIL PROTECTED] (edit in obvious way; spam precaution)
______________________________________________ [EMAIL PROTECTED] 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