title: R merge() by column names in one data frame, and a column in the other
body: <p>I am trying to use the merge function in R. I have a list of column names (Stock names) in some data frame D. I then have another data frame 'Info' where these Stock names are stored in a column, with a corresponding sector name in the next column. I need to merge these sector names to a row in D. </p>
  
  <p>If I were merging on 2 columns, I could use merge() directly and alter by.x and by.y and the emrged values would appear as extra columns. However, D has the name I am merging by as its column names, so I essentially want it to add on extra rows? The following code didn't work:</p>
  
  <pre><code>M&lt;-merge(D,Info[,c("Name","Sector")],by.x=colnames(D), by.y=c("Name"))
  </code></pre>
  
  <p>P.S I have searched around on SO, but nobody has precisely this problem. They have similar ones, but those approaches are not valid for this.</p>