title: Merge by row number in R
body: <p>I am trying to merge two data frames, <code>dat1</code> and <code>dat2</code>.</p>
  
  <p><code>dat1</code> is an n x 65 data frame, whose <code>rownames</code> correspond to specific values in <code>dat2</code>. Here's a smaller, toy example:</p>
  
  <pre><code> year &lt;- c(1998, 2001, 2002, 2004, 2008)
   make &lt;- c("Ford", "Dodge", "Toyota", "Tesla", "Jeep") 
   model &lt;- c("Escape", "Ram", "Camry", "Model S", "Wrangler")
   price &lt;- c(4750.00, 14567.00, 20000.00, 60123.00, 18469.00) 
   dat1 &lt;- data.frame(year, make, model, price)
  </code></pre>
  
  <p><code>dat2</code> is an nx1 vector with a single column called <code>rownumber</code>. It contains row numbers from <code>dat1</code> which are of interest.  Here's an example:</p>
  
  <pre><code>dat2 &lt;- as.data.frame(c(12, 45, 56, 123))
  colnames(dat1)[1] &lt;- "rownumber" 
  </code></pre>
  
  <p>I attempt to merge both data frames as follows:</p>
  
  <pre><code>dat3 &lt;- merge(dat1, dat2, by = "row.names", all.x = TRUE, all.y = FALSE)
  </code></pre>
  
  <p>The problem is that <code>dat3</code> contains two columns, <code>row.names</code> and <code>rownumber</code> which do not match.  For example, in row one of <code>dat3</code>, <code>row.names</code> = 1, but <code>rownumber</code> = 777. </p>
  
  <p>Any thoughts on how to resolve this? Thanks in advance. </p>