title: In R, how to return the name from columns A through E based on matching data in column in F?
body: <p>I want to return the column name from columns <code>A</code> through <code>E</code> based on matching data in column in <code>F</code>. I then want to return the value into a new column <code>G</code>.</p>
  <p>For example:</p>
  <pre><code>df &lt;- structure(list(A = c(-0.113802816901408, -0.613802816901408, 
  0.136197183098592, 0.126197183098592, 0.286197183098592), B = c(-0.294595070422536, 
  -0.504595070422535, 0.125404929577464, 0.135404929577464, 0.275404929577465
  ), C = c(-0.277065727699531, -0.507065727699531, 0.282934272300469, 
  0.0729342723004693, 0.122934272300469), D = c(-0.222699530516432, 
  -0.132699530516432, -0.162699530516432, 0.127300469483568, -0.0126995305164321
  ), E = c(-0.246845657276995, -0.426845657276995, -0.186845657276995, 
  0.133154342723005, 0.113154342723004), F = c(-0.222699530516432, 
  -0.426845657276995, 0.136197183098592, 0.133154342723005, 0.275404929577465
  )), row.names = c(NA, 5L), class = &quot;data.frame&quot;)
  </code></pre>
  <p>So the vector for column <code>G</code> should end up being: <code>D</code>, <code>E</code>, <code>A</code>, <code>E</code>, <code>B</code></p>
  <p>Ideally, if there are multiple matches (which I don't think my example has), it would be good to send such information to a new column or perhaps to throw an error. This second issue is not as important though.</p>