Q:

How to convert matrix into array?

I have a large data set and i want to convert it into array. But for instance lets have a simple example.
I have following matrix
`\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrrrr}
\hline
& 1 & 2 & 3 & 4 & 5 & 6 \\ 
\hline
1 &   1 &  11 &  21 &  31 &  41 &  51 \\ 
2 &   2 &  12 &  22 &  32 &  42 &  52 \\ 
3 &   3 &  13 &  23 &  33 &  43 &  53 \\ 
4 &   4 &  14 &  24 &  34 &  44 &  54 \\ 
5 &   5 &  15 &  25 &  35 &  45 &  55 \\ 
6 &   6 &  16 &  26 &  36 &  46 &  56 \\ 
7 &   7 &  17 &  27 &  37 &  47 &  57 \\ 
8 &   8 &  18 &  28 &  38 &  48 &  58 \\ 
9 &   9 &  19 &  29 &  39 &  49 &  59 \\ 
10 &  10 &  20 &  30 &  40 &  50 &  60 \\ 
\hline
\end{tabular}
\end{center}
\end{table}
`

What i need is to convert this matrix into array of dimension (5,6,2), in which first matrix contains first five rows of "x" and second matrix will contain last 5 rows.
I have tried 
dim(x)<-c(5,6,2)

which makes the matrix-1 with 1:30 consecutive numbers and then matrix-2 with 31:60 consecutive numbers. Which is not my requirement. 
Thanks in advance.

A:

What you offered is a LaTeX representation. The same matrix in R would be
M <- matrix(1:60, ncol=6)  # a 10 x 6 matrix

Consider using abind from package "abind":
require(abind)
abind( M[1:5,], M[6:10, ], along=3 )
#-----------------
, , 1

     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1   11   21   31   41   51
[2,]    2   12   22   32   42   52
[3,]    3   13   23   33   43   53
[4,]    4   14   24   34   44   54
[5,]    5   15   25   35   45   55

, , 2

     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    6   16   26   36   46   56
[2,]    7   17   27   37   47   57
[3,]    8   18   28   38   48   58
[4,]    9   19   29   39   49   59
[5,]   10   20   30   40   50   60

If you didn't want to use an outside package and would settle for the transposed version of each slice, then transpose first and then re-dimension. You cannot transpose an array, however, there is an aperm function you could look at:
Mt <- t(M)
dim(Mt) <- c(6, 5, 2)
Mt
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]   11   12   13   14   15
[3,]   21   22   23   24   25
[4,]   31   32   33   34   35
[5,]   41   42   43   44   45
[6,]   51   52   53   54   55

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]    6    7    8    9   10
[2,]   16   17   18   19   20
[3,]   26   27   28   29   30
[4,]   36   37   38   39   40
[5,]   46   47   48   49   50
[6,]   56   57   58   59   60

The aperm solution:
> aperm(Mt, c(2,1,3))
, , 1

     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1   11   21   31   41   51
[2,]    2   12   22   32   42   52
[3,]    3   13   23   33   43   53
[4,]    4   14   24   34   44   54
[5,]    5   15   25   35   45   55

, , 2

     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    6   16   26   36   46   56
[2,]    7   17   27   37   47   57
[3,]    8   18   28   38   48   58
[4,]    9   19   29   39   49   59
[5,]   10   20   30   40   50   60

