title: R converting list to array
body: <p>Hi I have a quick question about converting a list of data.frames into an array (I prefer the latter format for plotting and manipulation).</p>
  
  <p>I have the following code which just about works but I am not getting the loop right and wondered if someone could point me to what I am doing wrong.</p>
  
  <p>What I want to do is fill an array with the values of one of the columns from each of the different data.frames in my list of data.frames.</p>
  
  <pre><code># list all the files in a directory
  data.dir = "/data/output"
  
  # list all the files to plot
  files &lt;- list.files(data.dir, full=TRUE, pattern="Fields_grid*")
  
  # cat them together into one data frame
  data &lt;- lapply( files,  read.csv, header=FALSE, skip=26)
  
  # calc no. of files
  nfiles &lt;- length(files)
  
  # set up an empty array to fill with data
  z &lt;- array( NA, dim=c(length(x), length(y), nfiles ))
  
  # loop through all the data.frames/files 
  for (i in 1:length(nfiles)) {
  
  # calc index's of lists
  x &lt;- sort(unique( data[[i]]$V3))
  y &lt;- sort(unique( data[[i]]$V4))
  indx &lt;- match( data[[i]]$V3, x)
  indy &lt;- match( data[[i]]$V4, y)
  
  # fill array
  z[ cbind( indx, indy, i)] &lt;- data[[i]]$V5 }
  </code></pre>
  
  <p>I know this is a terrible question as I can not reproduce the result I get, but I hope you can understand my issue. When I look at z[,,1] this contains data but z[,,2] to z[,,nfiles] contains NA (i.e. my loop has not worked). I guess its something to do with the indexing but I really can't see what I have done wrong.</p>
  
  <p>Again apologies for an opaque question and thanks for having a look!</p>