title: Choose one cell per row in data frame
body: <p>I have a vector that tells me, for each row in a date frame, the column index for which the value in this row should be updated.</p>
  
  <pre><code>&gt; set.seed(12008); n &lt;- 10000; d &lt;- data.frame(c1=1:n, c2=2*(1:n), c3=3*(1:n))
  &gt; i &lt;- sample.int(3, n, replace=TRUE)
  &gt; head(d); head(i)
    c1 c2 c3
  1  1  2  3
  2  2  4  6
  3  3  6  9
  4  4  8 12
  5  5 10 15
  6  6 12 18
  [1] 3 2 2 3 2 1
  </code></pre>
  
  <p>This means that for rows 1 and 4, c3 should be updated; for rows 2, 3 and 5, c2 should be updated (among others). What is the cleanest way to achieve this in R using vectorized operations, i.e, without <code>apply</code> and friends? <strong>EDIT:</strong> And, if at all possible, without R loops?</p>
  
  <p>I have thought about transforming <code>d</code> into a matrix and then address the matrix elements using an one-dimensional vector. But then I haven't found a clean way to compute the one-dimensional address from the row and column indexes.</p>