This does the trick.

apply(sapply(xyz_indices, function(xyz) edm[xyz[1], xyz[2], xyz[3], ]), 1,
mean)

Jean


On Fri, Dec 27, 2013 at 7:28 AM, Morway, Eric <emorway@usgs.gov> wrote:

> In the larger problem I'm attempting to solve, I read a 2Gb file
> into a 4D array, where the first 3 dimensions are related to space
> (x, y, z), and the 4th dimension is time.  My goal is to find the
> average of specific x, y, z-indices for each time step.
>
> A small, reproducible example starts like this:
>
> edm <- array(rnorm(20*20*4*50), dim=c(20,20,4,50))
> xyz_indices <- list(c(2,10,1), c(4,5,1), c(6,7,1), c(19,13,1))
>
> What's the best way to calculate the average of the x, y, z
> indices specified in the "xyz_indices" list for each of the 50 time
> steps represented by the 4th dimension of "edm"?  In other words,
> I want to end up with a time series of length 50 where each value of
> the series is the average of the 4 xyz_indices.
>
>
> Eric
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

