title: R issues with merge/rbind/concatenate two data frames
body: <p>I am a beginner with R so i apologise in advance if the question was asked elsewhere. Here is my issue:</p>
  
  <p>I have two data frames, df1 and df2, with different number of rows and columns. The two frames have only one variable (column) in common called "customer_no". I want the merged frame to match records based on "customer_no" and by rows in df2 only.Both data.frames have multiple rows for each customer_no.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>merged.df &lt;- (df1, df2, by="customer_no",all.y=TRUE)
  </code></pre>
  
  <p>The problem is that this assigns values of df1 to df2 where instead it should be empty. My questions are:</p>
  
  <p>1) How can I tell the command to leave the unmatched columns empty?
  2) How can I see from the merged file which row came from which df? I guess if I resolve the above question this should be easy to see by the empty columns.</p>
  
  <p>I am missing something in my command but don't know what. If the question has been answered somewhere else, would you be still kind enough to rephrase it in English here for an R beginner?</p>
  
  <p>Thanks!</p>
  
  <p>Data example:</p>
  
  <pre><code>df1:
  customer_no  country  year
    10           UK     2001
    10           UK     2002
    10           UK     2003
    20           US     2007
    30           AU     2006
  
  
  df2:          
  customer_no   income
    10            700
    10            800
    10            900 
    30            1000
  </code></pre>
  
  <p>Merged file should look like this:</p>
  
  <pre><code>merged.df:
   customer_no   income  country   year
       10                  UK      2001
       10                  UK      2002
       10                  UK      2003
       10         700
       10         800
       10         900
       30                  AU      2006
       30         1000
  </code></pre>
  
  <p>So:
  It puts the columns all together, it adds the values of df2 right after the last one of df1 based on same customer_no and matches only customer_no from df2 (merged.df does not have customer_no 20). Also, it leaves empty all the other cells.</p>
  
  <p>In STATA I use append but not sure in R...perhaps join?</p>
  
  <p>THANKS!!</p>