title: How to convert a data frame to a 3d array in R
body: <p>I have a data frame that I want to convert to a three-dimensional array. One of the columns in the data frame should serve as the grouping variable for splitting the frame into 2d matrices that can be combined into the array. In the following minimal working example, the data frame should be split into matrices by the variable "i", then combined into a 4x4x2 array. The solution should be practical for large data sets and ideally could be generalized to convert a data frame into a n dimensional array.</p>
  
  <pre><code># Make reproducible 
  set.seed(123)
  
  df &lt;- {
    data.frame(i=rep(1:2, each=4),
               x=rep(rep(0:1, each=2), 2),
               y=rep(rep(0:1, 2), 2),
               l=rnorm(8))
  }
  
  df
  #   i x y           l
  # 1 1 0 0 -0.56047565
  # 2 1 0 1 -0.23017749
  # 3 1 1 0  1.55870831
  # 4 1 1 1  0.07050839
  # 5 2 0 0  0.12928774
  # 6 2 0 1  1.71506499
  # 7 2 1 0  0.46091621
  # 8 2 1 1 -1.26506123
  </code></pre>
  
  <p>Note: I suspect that Hadley Wickham's plyr may provide the needed tool, perhaps daply?</p>