title: How to iterate over each dimension of a multi-dimensional array, or turn an array into a list of matrices: R
body: <p>I have this example array in R:</p>
  <pre><code>vec1 &lt;- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
  vec2 &lt;- c(10, 11, 12, 13, 14, 15, 16, 17, 18)
  
  exampleArray &lt;- array(c(vec1, vec2), dim = c(2, 3, 3))
  </code></pre>
  <p>It produces the following three matrices in the form of an array:</p>
  <pre><code>&gt; exampleArray
  , , 1
  
       [,1] [,2] [,3]
  [1,]    1    3    5
  [2,]    2    4    6
  
  , , 2
  
       [,1] [,2] [,3]
  [1,]    7    9   11
  [2,]    8   10   12
  
  , , 3
  
       [,1] [,2] [,3]
  [1,]   13   15   17
  [2,]   14   16   18
  </code></pre>
  <p>I have done the computations to the array I want to do, and now I want to write a function that iterates over each matrix, or undoes the array into a list of matrices. I was thinking of using a for loop similar in structure to iterating over the rows or columns of a matrix, but I couldn't find a way to produce a list of values through the third dimension of an array. I could make this work if I could turn this array into a list of matrices, so please provide that as an answer too.</p>
  <p>Do note that my actual data is huge, I have a folder of arrays, all different in the number of matrices they contain (IE the third dimension length), though all matrices are the same dimensions (IE lengths of dimensions 1 and 2 are equal across all arrays), so I would like the solution to be dynamic in that I don't need to manually type in exampleArray[,,1], etc, etc.</p>
  <p>This is not my first time asking basic and stupid questions here, no need to nice, humiliation is acceptable. Though an answer is appreciated.</p>