Richard A. O'Keefe wrote:
Jerome Asselin <[EMAIL PROTECTED]> suggests this:
arr <- array(rnorm(27),c(3,3,3))
dimarr <- dim(arr)
tmparr <- array(1:prod(dimarr),dimarr)
sapply(c(3),function(x,tmparr) which(tmparr==x,T),tmparr=tmparr)
sapply(c(3,17,13,5),functi
Jerome Asselin <[EMAIL PROTECTED]> suggests this:
arr <- array(rnorm(27),c(3,3,3))
dimarr <- dim(arr)
tmparr <- array(1:prod(dimarr),dimarr)
sapply(c(3),function(x,tmparr) which(tmparr==x,T),tmparr=tmparr)
sapply(c(3,17,13,5),function(x,tmparr) which(tmparr==
"Buchsbaum, Brad (NIH/NIMH)" <[EMAIL PROTECTED]> writes:
> Hi,
>
> Suppose I have a multidimensional array:
>
> tmp <- array(1:8, c(2,2,2))
>
> is there a function out there that, given a one-dimensional array index,
> will
> return the separate indices for each array dimension?
>
> for instan
Try this... Perhaps this will help you do what you want. The key idea is
to use which() with option arr.ind = TRUE.
arr <- array(rnorm(27),c(3,3,3))
dimarr <- dim(arr)
tmparr <- array(1:prod(dimarr),dimarr)
sapply(c(3),function(x,tmparr) which(tmparr==x,T),tmparr=tmparr)
sapply(c(3,17,13,5),func
I believe that the function below satisfies the request:
rev.index <-
function (x, dims)
{
ld <- length(dims)
cumdim <- cumprod(dims)
ans <- array(NA, c(length(x), ld))
ans[, ld] <- (x-1) %/% cumdim[ld - 1] + 1
ans[, ld-1] <- (x-1) %% cumdim[ld - 1] + 1
if
Hi,
Suppose I have a multidimensional array:
tmp <- array(1:8, c(2,2,2))
is there a function out there that, given a one-dimensional array index,
will
return the separate indices for each array dimension?
for instance, tmp[8] is equivalent to tmp[2,2,2]. I'd like to derive the
vector (2,2,2)