[R] do.call() and aperm()
Tony Plate
tplate at blackmesacapital.com
Tue Oct 21 18:17:05 CEST 2003
I've also been thinking about how to specify that 'along' should be
length(dim)+1. At the moment one can specify any number from 0 up to
length(dim)+1, but as you point out you have to spell out length(dim)+1 as
the value for the along argument. It would possible to make abind()
automatically calculate along=length(dim)+1 when given along=NA, or
along=-1, or along="+1". Any preferences?
-- Tony Plate
At Tuesday 04:48 PM 10/21/2003 +0100, Robin Hankin wrote:
>Hi everyone
>
>I've been playing with do.call() but I'm having problems understanding it.
>
>I have a list of "n" elements, each one of which is "d" dimensional
>[actually an n-by-n-by ... by-n array]. Neither n nor d is known in
>advance. I want to bind the elements together in a higher-dimensional
>array.
>
>Toy example follows with d=n=3.
>
>f <- function(n){array(n,c(3,3,3))}
>x <- sapply(1:3,f,simplify=FALSE)
>
>Then what I want is
>
>ans <- abind(x[[1]] , x[[2]] , x[[3]] , along=4)
>
>[abind() is defined in library(abind)].
>
>Note that dim(ans) is c(3,3,3,3), as required.
>
>PROBLEM: how do I do tell do.call() that I want to give abind() the
>extra argument along=4 (in general, I want
>along=length(dim(x[[1]]))+1)?
>
>
>Oblig Attempt:
>
>jj <- function(...){abind(... , along=4)}
>do.call("jj" , x)
>
>This works, because I know that d=3 (and therefore use along=4), but
>it doesn't generalize easily to arbitrary d. I'm clearly missing
>something basic. Anyone?
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list