title: Selecting different elements of an R dataframe (one for each row, but possibly different columns) without using loops
body: <p>Say I have a <code>data.frame</code> of arbitrary dimensions (<code>n</code> by <code>p</code>). I want to extract a vector of length <code>n</code> from that <code>data.frame</code>, one element in the vector per row in the <code>data.frame</code>. However, the column in which each element lies may vary by row.  Is there a way to do this without loops?</p>
  
  <p>For example, if I have the following (3x3) data frame, called say DATA</p>
  
  <pre><code>X   Y   Z
  1  17  43
  3   4   2
  6   9   0
  </code></pre>
  
  <p>I want to extract one scalar value from DATA per row. I have a vector, call it column.list, c(1,3,1) (arbitrarily selected in this case) which gives the column index for the elements I want, where the kth element of column.list is the column index for row k in DATA. How do I do this without loops? I want to avoid loops because I am using this repeatedly in a simulation study that will take a lot of running time even without loops, and the row number might be 100,000 or so.  Much appreciated! </p>