title: Transforming a table in a 3D array in R
body: <p>I have a matrix:</p>
  
  <pre><code>R&gt; pippo.m
       [,1] [,2] [,3] [,4]
  [1,]    1    2    3    4
  [2,]    5    6    7    8
  [3,]    9   10   11   12
  [4,]   13   14   15   16
  [5,]   17   18   19   20
  [6,]   21   22   23   24
  </code></pre>
  
  <p>and I would like to transform this matrix in a 3D array with dim=(2,4,3). Passing through the transponse of pippo.m I am able to obtain a similar result but with columns and rows rotated. </p>
  
  <pre><code>&gt; pippo.t &lt;- t(pippo.m)
  
  &gt; pippo.vec &lt;- as.vector(pippo.t)
  
  &gt; pippo.arr &lt;- array(pippo.vec,dim=c(4,2,3),dimnames=NULL)
  
  &gt; pippo.arr
   , , 1
       [,1] [,2]
   [1,]    1    5
   [2,]    2    6
   [3,]    3    7
   [4,]    4    8
  
   , , 2
       [,1] [,2]
  [1,]    9   13
  [2,]   10   14
  [3,]   11   15
  [4,]   12   16
  
  , , 3
       [,1] [,2]
  [1,]   17   21
  [2,]   18   22
  [3,]   19   23
  [4,]   20   24
  </code></pre>
  
  <p>Actually, I would prefer to mantain the same distribution of the original data, as rows and colums represent longitude and latitude and the third dimension is time. So I would like to obtain something like this:</p>
  
  <pre><code>pippo.a 
  , , 1
       [,1] [,2] [,3] [,4]
  [1,]    1    2    3    4
  [2,]    5    6    7    8
  
  
  , , 2
       [,1] [,2] [,3] [,4]
  [1,]    9   10   11   12
  [2,]   13   14   15   16
  
  
  , , 3
       [,1] [,2] [,3] [,4]
  [1,]   17   18   19   20
  [2,]   21   22   23   24
  </code></pre>
  
  <p>How can I do?</p>