Skip to content
Prev 78161 / 398502 Next

Descriptive statistics for tables

If I understand the request, he wants to take a large number of matrices 
of identical size and stack them into a three dimentional array, and 
then calculate statistics on the the third dimension.   If the multiple 
arrays have object names they can be combined into a 3-d array

 > a <- matrix(rep(1,9),ncol=3)
 > b <- matrix(rep(2,9),ncol=3)
 > c <- matrix(rep(3,9),ncol=3)
 > z <- array(c(a,b,c),dim=c(3,3,3))

 > z
, , 1

      [,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
[3,]    1    1    1

, , 2

      [,1] [,2] [,3]
[1,]    2    2    2
[2,]    2    2    2
[3,]    2    2    2

, , 3

      [,1] [,2] [,3]
[1,]    3    3    3
[2,]    3    3    3
[3,]    3    3    3


and then specific dimensions can be summarized

 > mean(z[1,1,])
[1] 2

 > sd(z[1,1,])
[1] 1

I don't know of any easy way to combine all the 2-d matrices other than 
listing them by name in a c() function in the array statement.  If they 
were cleverly names perhaps a for loop could be used.

Dave
Jean Eid wrote: