title: How to index and multiply two matrices efficiently?
body: <p>I have two matrices "A", "B", and a data frame "C". They are</p>
  
  <pre><code>A &lt;- matrix(1:10, nrow = 2) 
  colnames(A) &lt;- letters[1:5]
  
  B &lt;- matrix(11:16, nrow = 2)
  colnames(B) &lt;- letters[6:8]
  
  C &lt;- data.frame(ix1 = c("a", "d"), ix2 = c("f", "h"))
  </code></pre>
  
  <p>I want to create a vector "vec" with length 2 and values </p>
  
  <pre><code>vec[1] = A[,"a"] %*% B[,"f"]
  vec[2] = A[,"d"] %*% B[,"h"]
  </code></pre>
  
  <p>This can be done easily with a <code>for</code> loop, but it is time consuming when the sizes of "A", "B" and "C" grow. How to do it efficiently?</p>