title: merge when have different levels of by factor R
body: <p>I want to double check something. I'm trying to merge a large dataset into a smaller dataset. My large dataframe has observations that are not included in the small dataset. I cannot obtain a simple merge with my dataframes using the standard code</p>
  
  <pre><code>x&lt;-merge(df1,df2) ###default is all=FALSE. 
                    ###output from this code produces a df with 49 rows instead of 13
  </code></pre>
  
  <p>have also used;</p>
  
  <pre><code>x&lt;-merge(df1,df2, by='noms')  ##output produces 49 rows instead of 13
  </code></pre>
  
  <p>After much reading and checking for people who have alreday asked this question e.g., <a href="https://stackoverflow.com/questions/17626387/merge-2-data-frames-discard-unmatched-rows">Merge 2 data frames, discard unmatched rows</a> i came across this <a href="https://stat.ethz.ch/pipermail/r-help/2006-September/113148.html" rel="nofollow noreferrer">https://stat.ethz.ch/pipermail/r-help/2006-September/113148.html</a> which says that there is no unambiguous way to fix this problem. </p>
  
  <p>Is this still the case? apologies if this has been answered somewhere already, I've tried reading the core documents ?merge and posts on stackoverflow - but am now at a loose end. </p>
  
  <p>my dfs are below</p>
  
  <p><strong>Small dataframe</strong></p>
  
  <pre><code> noms fruits apple orange kiwi all_comb comb numbers
  1  mary  apple     1      0    0        1    1       1
  2  mary  grape     0      0    0        0    1       2
  3  mary orange     0      1    0        0    1       3
  4  mary  apple     1      0    0        1    1       4
  5  john banana     0      0    0        0    1       1
  6  john  apple     1      0    0        1    1       2
  7  john  apple     1      0    0        1    1       3
  8  john  apple     1      0    0        1    1       4
  9  lucy   kiwi     0      0    1        0    1       1
  10 lucy orange     0      1    0        0    1       2
  11 lucy  apple     1      0    0        1    1       3
  12 lucy  berry     0      0    0        0    1       4
  13  tom orange     0      1    0        0    1       1
  </code></pre>
  
  <p><strong>Large dataframe</strong></p>
  
  <pre><code>  noms age
  1  jane  50
  2  jane  50
  3  jane  50
  4  jane  50
  5  mary  65
  6  mary  65
  7  mary  65
  8  mary  65
  9  john  34
  10 john  34
  11 john  34
  12 john  34
  13  pat  65
  14  pat  65
  15  pat  65
  16 lucy  89
  17 lucy  89
  18 lucy  89
  19 lucy  89
  20  tom  12
  </code></pre>
  
  <p><strong>Desired output</strong></p>
  
  <p>df</p>
  
  <pre><code>  noms fruits apple orange kiwi all_comb comb numbers age
  1  mary  apple     1      0    0        1    1       1  65
  2  mary  grape     0      0    0        0    1       2  65
  3  mary orange     0      1    0        0    1       3  65
  4  mary  apple     1      0    0        1    1       4  65
  5  john banana     0      0    0        0    1       1  34
  6  john  apple     1      0    0        1    1       2  34
  7  john  apple     1      0    0        1    1       3  34
  8  john  apple     1      0    0        1    1       4  34
  9  lucy   kiwi     0      0    1        0    1       1  89
  10 lucy orange     0      1    0        0    1       2  89
  11 lucy  apple     1      0    0        1    1       3  89
  12 lucy  berry     0      0    0        0    1       4  89
  13  tom orange     0      1    0        0    1       1  12
  </code></pre>