title: Mean of each row on selected indices
body: <p>I have a matrix holding numerical data with 7 columns, and I want to calculate the mean of selected entries of each row (i.e. only 2 numbers from each row). Another matrix contains information of which entries are selected for each row. What's the best way to do this in R?</p>
  
  <pre><code>       a      b      c       d      e       f       g
  [1,]  0.0068  0.0240 0.0014  0.0035 0.0029  0.0293  0.0384
  [2,]  0.0197  0.0325 0.0016  0.0163 0.0030  0.0234 -0.0937
  [3,] -0.0194 -0.0265 0.0045 -0.0068 0.0029  0.0265  0.0997
  [4,]  0.0048  0.0540 0.0015  0.0030 0.0031 -0.0090  0.0580
  [5,]  0.0369  0.0112 0.0015  0.0072 0.0029  0.0597 -0.0134
  [6,] -0.0025 -0.0325 0.0014  0.0031 0.0034  0.0757  0.0385
  
  
       [,1] [,2]
  [1,]    2    1
  [2,]    2    7
  [3,]    2    6
  [4,]    6    7
  [5,]    7    2
  [6,]    7    6
  </code></pre>