title: merging data in R
body: <p>I have a data set A</p>
  
  <pre><code>paper_id author_id
    1       521630
    1       1611750
    2       9
    3       627950
    4       1456512
    8       15
    ........
  </code></pre>
  
  <p>and a data set B</p>
  
  <pre><code>author_id    author_name        author_affiliation
      9       Ernest Jordan            Cambridge                                                    
      14         K. MORIBE               NA                                                 
      15     D. Jakominich               NA                                                 
      25     William H. Nailon                                                                
      37     P. B. Littlewood    Cavendish Laboratory|Cambridge University 
      ........       
  </code></pre>
  
  <p>I want to merge these two data sets in such a way so that merging is done through author_id but result should be seen like:</p>
  
  <pre><code>paper id    author_id        author_name     author_affiliation
    2            9             Ernest Jordan     Cambridge
    8            15            D. Jakominich       NA
  </code></pre>
  
  <p>That is I want to have data in the order by paper_id only and merging is performed on the author_id, such that all the paper_id order doesnt get disturbed.</p>
  
  <p>From what I am doing is:</p>
  
  <pre><code>b&lt;-merge(A,B,by="author_id")
  </code></pre>
  
  <p>and I am getting. In this the paper_id is getting disturbed </p>
  
  <pre><code> author_id paper_id       author_name      author_affiliation
       9     1468598       Ernest Jordan       cambridge
       9     1682105       Ernest Jordan       cambridge
  </code></pre>
  
  <p>and then I have to sort this output by sorting through paper_id column.Its a very inefficient way.</p>
  
  <p>How could this be done.</p>
  
  <p>Thanks</p>