Skip to content
Prev 273474 / 398506 Next

mean of 3D arrays

Hi:

There are a few ways to do this. If you only have a few arrays, you
can simply add them and divide by the number of arrays. If you have a
large number of such arrays, this is inconvenient, so an alternative
is to ship the arrays into a list and use the Reduce() function. For
your example,

L <- list(x1, x2, x3)
Reduce('+', L)/length(L)

would work. If you have many such arrays in separate files, you can
always use lapply() in conjunction with a suitable read function with
an input vector that contains the file names to be read, of the
general form

L <- lapply(<vector of file names>, <function to read data>)

with the idea that the read function passes arrays into the list components.

Here's a simple toy example with three small matrices to illustrate
proof of concept:
[,1] [,2] [,3]
[1,]   -2    1    4
[2,]   -1    2    5
[3,]    0    3    6
[,1] [,2] [,3]
[1,]   -2    1    4
[2,]   -1    2    5
[3,]    0    3    6

HTH,
Dennis
On Wed, Oct 5, 2011 at 6:00 AM, Martin Batholdy <batholdy at googlemail.com> wrote: