title: R Data.Table Join - Transform 'Missing' from NA to a Default Value
body: <p>I am trying to join two data tables.  The first (called 'left' below) has a set of keys (column 'k').  The second ('right') has a similar set of keys along with values for each key.  I want to update the 'left' data in-place so that it has the value from 'right' where it exists.  But in the case that it does not exist, a default value rather than NA should be populated.</p>
  
  <p>I created a function 'default' that will replace NAs with a default value.</p>
  
  <pre><code>default &lt;- function(value, default) {
      value[is.na(value)] &lt;- default
      return(value)
  }
  </code></pre>
  
  <p>I don't understand why the following does not work.</p>
  
  <pre><code>left &lt;- data.table(k=c(1,2,3,4,NA), key="k")
  right &lt;- data.table(k=c(1,2), value=c("a","b"), key="k")
  left[right, value := default(value,"none")]
  </code></pre>
  
  <p>Actual result...</p>
  
  <pre><code>&gt; left
      k value
  1: NA    NA
  2:  1     a
  3:  2     b
  4:  3    NA
  5:  4    NA
  </code></pre>
  
  <p>Expected result...</p>
  
  <pre><code>    k value
  1: NA    none
  2:  1     a
  3:  2     b
  4:  3    none
  5:  4    none
  </code></pre>
  
  <p>Thanks for your help.</p>