Skip to content
Prev 317536 / 398503 Next

list of matrices --> array

On Feb 13, 2013, at 10:03 PM, Murat Tasan wrote:

            
I think the built-in function you seek is `simplify2array`:

# gives 4 x 5 x 2
 > simplify2array(my_list)
, , 1

      [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    9   13   17
[2,]    2    6   10   14   18
[3,]    3    7   11   15   19
[4,]    4    8   12   16   20

, , 2

      [,1] [,2] [,3] [,4] [,5]
[1,]   20   16   12    8    4
[2,]   19   15   11    7    3
[3,]   18   14   10    6    2
[4,]   17   13    9    5    1

 > # 2 x 4 x 5
  aperm( simplify2array(my_list), c(3,1,2) )


  # 4 x 2 x 5
 > aperm( simplify2array(my_list), c(1,3,2) )