title: Preventing duplicate columns when merging with data.table
body: <p>I have two data tables which have partly similar column names:</p>
  
  <pre><code>   dfA &lt;- read.table(
    text = "A   B   C   D   E   F   G   iso   year   matchcode
    1   0   1   1   1   0   1   0   NLD   2010   NLD2010
    2   1   0   0   0   1   0   1   NLD   2014   NLD2014
    3   0   0   0   1   1   0   0   AUS   2010   AUS2010
    4   1   0   1   0   0   1   0   AUS   2006   AUS2006
    5   0   1   0   1   0   1   1   USA   2008   USA2008
    6   0   0   1   0   0   0   1   USA   2010   USA2010
    7   0   1   0   1   0   0   0   USA   2012   USA2012
    8   1   0   1   0   0   1   0   BLG   2008   BLG2008
    9   0   1   0   1   1   0   1   BEL   2008   BEL2008
    10   1   0   1   0   0   1   0  BEL   2010   BEL2010",
    header = TRUE
  )
  
     dfB &lt;- read.table(
    text = "A   B   C   D   H   I   J   iso   year   matchcode
    1   0   1   1   1   0   1   0   NLD   2009   NLD2009
    2   1   0   0   0   1   0   1   NLD   2014   NLD2014
    3   0   0   0   1   1   0   0   AUS   2011   AUS2011
    4   1   0   1   0   0   1   0   AUS   2007   AUS2007
    5   0   1   0   1   0   1   1   USA   2007   USA2007
    6   0   0   1   0   0   0   1   USA   2011   USA2010
    7   0   1   0   1   0   0   0   USA   2013   USA2013
    8   1   0   1   0   0   1   0   BLG   2007   BLG2007
    9   0   1   0   1   1   0   1   BEL   2009   BEL2009
    10   1   0   1   0   0   1   0  BEL   2012   BEL2012",
    header = TRUE
  )
  library(data.table)
  setDT(dfA)
  setDT(dfB)
  </code></pre>
  
  <p>To merge the data.tables I will do the following:</p>
  
  <pre><code>dfA &lt;- dfA[dfB, on = .(iso, year), roll = "nearest", nomatch = 0]
  </code></pre>
  
  <p>This will however, apart from the desired duplicate column <code>matchcode</code> also create the undesired duplicate columns <code>A, B, C, D</code>. Because of the number of merges I need to do, that would get too messy.</p>
  
  <p>Is there a way to exclude duplicate columns from the merging process without explicitly referring to them? If not, how can I do so by explicitly referring to them. If not, can I remove them afterwards without explicitly referring to the duplicates? For example by removing all columns which look like `i.columnname' ?</p>
  
  <p>The preferred output would be as follows: </p>
  
  <pre><code>#    A B C D E F G iso year matchcodeA H I J matchcodeB
  # 1: 1 0 0 0 1 0 1 NLD  2014  NLD2014  1 0 1    NLD2014
  # 2: 0 0 0 1 1 0 0 AUS  2011  AUS2010  1 0 0    AUS2011
  # 3: 1 0 1 0 0 1 0 AUS  2007  AUS2006  0 1 0    AUS2007
  # 4: 0 0 1 0 0 0 1 USA  2011  USA2010  0 0 1    USA2010
  # 5: 0 1 0 1 0 0 0 USA  2013  USA2012  0 0 0    USA2013
  # 6: 0 1 0 1 1 0 1 BEL  2009  BEL2008  1 0 1    BEL2009
  # 7: 0 1 1 1 0 1 0 NLD  2009  NLD2010  0 1 0    NLD2009
  # 8: 0 1 0 1 0 1 1 USA  2007  USA2008  0 1 1    USA2007
  # 9: 0 1 0 1 0 0 0 USA  2011  USA2012  0 0 1    USA2010
  #10: 1 0 1 0 0 1 0 BEL  2009  BEL2010  1 0 1    BEL2009
  </code></pre>