title: r programming --- merge function returns column names with .x and .y
body: <p>While merging two tables, I can't control column names in the merge result. To explain my situation, let me use mtcars data:</p>
  
  <pre><code>#load mtcars data.frame
  data(mtcars)
  </code></pre>
  
  <p>Add a new column called 'car' that I will use as merging key</p>
  
  <pre><code>mtcars$car &lt;- row.names(mtcars)
  </code></pre>
  
  <p>Now create two mutually exclusive tables. </p>
  
  <pre><code>small &lt;- mtcars[mtcars$cyl == 4,]
  med.large &lt;- mtcars[mtcars$cyl &gt;4,]
  </code></pre>
  
  <p>Now when I do a left merge, I should get 'small' table back as the two tables are mutually exclusive:</p>
  
  <pre><code>merge(x = small, y = med.large, by = 'car', all.x=T)
  </code></pre>
  
  <p>this returns 'small' table back but every column appears twice with .x and .y extension with .y columns all NA (since the two tables have no common records) and looks like the following</p>
  
  <pre><code> car mpg.x cyl.x disp.x hp.x drat.x  wt.x qsec.x vs.x am.x gear.x carb.x mpg.y cyl.y
  
   1      Datsun 710  22.8     4  108.0   93   3.85 2.320  18.61    1    1       4      1    NA    NA
  </code></pre>
  
  <p>how can I get column names only once with column values from the primary merge table in this case LEFT table ('small').  I don't know how to avoid .x and .y. extension? </p>