title: Inner Join when Duplicates Exist for Joining Variable
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1299871/how-to-join-data-frames-in-r-inner-outer-left-right">How to join data frames in R (inner, outer, left, right)?</a>  </p>
  </blockquote>
  
  
  
  <p><a href="https://stackoverflow.com/questions/1299871/how-to-join-data-frames-in-r-inner-outer-left-right">This question</a> nicely goes over joins in R.</p>
  
  <p>And the <a href="http://en.wikipedia.org/wiki/Join_(SQL)#Inner_join" rel="nofollow noreferrer">Wikipedia article</a> on inner join is useful.</p>
  
  <p>I would like to reproduce this result in base R. I don't think the following work:</p>
  
  <pre><code>merge(employee,department,all=T)
  merge(employee,department)
  </code></pre>
  
  <p>because of the duplicates on the merging variable. </p>
  
  <p>However, <code>sqldf</code> works:</p>
  
  <pre><code>library(sqldf)
  sqldf("select * from employee  inner join department ON employee.DepartmentID = department.DepartmentID")
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>Does this mean that merge does not perform an inner join here.</p></li>
  <li><p>How can I accomplish this join in base R.</p></li>
  </ol>
  
  <p>Here are two data.frames to work with from the website and example above.</p>
  
  <pre><code>employee &lt;- structure(list(LastName = c("Rafferty ", "Jones", "Steinberg", 
  "Robinson", "Smith", "John"), DepartmentID = c("31", "33", "33", 
  "34", " 34", " .")), .Names = c("LastName", "DepartmentID"), class = "data.frame", row.names = c(NA, -6L))
  
  department &lt;- structure(list(DepartmentID = c(31L, 33L, 34L, 35L), DepartmentName =    structure(c(4L,2L, 1L, 3L), .Label = c("Clerical", "Engineering", "Marketing", "Sales"), class = "factor")), .Names = c("DepartmentID", "DepartmentName"), class = "data.frame", row.names = c(NA, -4L))
  </code></pre>