title: R use of lapply & sapply to interrogate list of matrices containing permuted data
body: <p>I have 3 datasets I permuted 10x. Each permutation of a dataset makes a column in 3 matrices (one matrix per dataset). These 3 matrices (<code>m1</code>,<code>m2</code>,<code>m3</code>) are in a list <code>L</code>. I would like to interrogate all possible combinations (10x10x10=1000) for each entry (in this case 4). I have used expand.grid to supply all combinations of column calls across the 3 matrices in the row of another matrix <code>M</code>:</p>
  
  <pre><code>M&lt;-expand.grid(seq(1:10),seq(1:10),seq(1:10))
  </code></pre>
  
  <p>Here is my data in a list:</p>
  
  <pre><code>m1&lt;-matrix(c(1,2,1,0,3,2,1,2,3,4),nrow=4, ncol=10)
  m2&lt;-matrix(c(m1[1,]),nrow=4,ncol=10)
  m3&lt;-matrix(c(m1[2,]),nrow=4,ncol=10)
  L&lt;-list(m1, m2, m3)
  </code></pre>
  
  <p>Can you help me use <code>do.call</code>, <code>cbind</code>, <code>lapply</code>/<code>sapply</code> to efficiently retrieve the column coordinates from M to interrogate the corresponding columns in the 3 matrices contained in L and bind them to a new matrix as such:</p>
  
  <pre><code>m.res&lt;-for (i in 1:nrow(M) { "get" L[[1:3]][M[i,]] }
  </code></pre>
  
  <p>For <code>i=1</code>, <code>m.res</code> would yield:</p>
  
  <pre><code>1 1 2
  2 3 2
  1 3 4
  0 1 0
  </code></pre>
  
  <p>I clearly need a tutorial for <code>lapply</code>/<code>sapply</code> as this should not be this difficult.</p>