data.table: replace existing value from field with the same name
<p>I need to merge some data form one data.table into another, and I know I can
inject fields from one data.table to another like so: </p>

<pre><code>df1 &lt;- data.table(Id = letters[1:5],a = 1:5)
df2 &lt;- data.table(Id = letters[1:3],a = 7:9,b=7:9)
setkey(df1,Id)
setkey(df2,Id)
df1[df2,b:=b][]
#&gt;    Id a  b
#&gt; 1:  a 1  7
#&gt; 2:  b 2  8
#&gt; 3:  c 3  9
#&gt; 4:  d 4 NA
#&gt; 5:  e 5 NA
</code></pre>

<p>but that idiom does not work when the field already exists in <code>df1</code>:</p>

<pre><code>df1[df2,a:=a][]
#&gt;    Id a
#&gt; 1:  a 1
#&gt; 2:  b 2
#&gt; 3:  c 3
#&gt; 4:  d 4
#&gt; 5:  e 5
</code></pre>

<p>I understand that df1 is unchanged by this assignment because the field <code>a</code> already exists in
<code>df1</code> and the reference to <code>a</code> in the right hand side of the assignment
resolves to that value, not the on in <code>df2</code>.  So how would I go about replacing the 
selected values in <code>df1$a</code> with those in <code>df2$a</code> to get the following:</p>

<pre><code>#&gt;    Id a
#&gt; 1:  a 7
#&gt; 2:  b 8
#&gt; 3:  c 9
#&gt; 4:  d 4
#&gt; 5:  e 5
</code></pre>