问题
Right now i have an array that is three dimensions. I have 200 rows, 200 columns and 24 "slices" in the third dimension
dim=c(200,200,24)
What I need is an average of the slices resulting in a new matrix. I need a 200 by 200 matrix and the values are the result of averaging up the appropriate slices. So in the location that would be row 1, col 1, I need the average of all the row 1's and col 1's from my array.
Is there a way to do this?
回答1:
Here's one attempt using a simple example:
test <- 1:8
dim(test) <- c(2,2,2)
, , 1
[,1] [,2]
[1,] 1 3
[2,] 2 4
, , 2
[,1] [,2]
[1,] 5 7
[2,] 6 8
Get your answer:
apply(test,c(1,2),mean)
[,1] [,2]
[1,] 3 5
[2,] 4 6
来源:https://stackoverflow.com/questions/15170668/matrix-of-averages-from-array