title: Elementwise multiplication of all matrices in a list in R
body: <p>I have a list of matrices. I need to multiply them together. Normally if we have matrix A and B and need matrix multiplication in R, we use</p>
  
  <pre><code>A*B
  </code></pre>
  
  <p>but I can't seem to make * work with lapply in this case. If my list of matrices is called l1 and I use lapply(l1,*) I get an error, and if I use lapply(l1,prod) it gives me the product of all elements within each matrix.</p>
  
  <p>Example:</p>
  
  <pre><code>&gt; l1
  [[1]]
       [,1] [,2]
  [1,]    2    5
  [2,]    3    7
  
  [[2]]
       [,1] [,2]
  [1,]    3    7
  [2,]    5    9
  
  [[3]]
       [,1] [,2]
  [1,]    5    8
  [2,]    1    2
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code> l1
        [,1] [,2]
  [,1]   30   280
  [,2]   15   126
  </code></pre>