title: Replace values of data.table with values from another data.table
body: <p>I have a dataset with 300 columns and 1000 rows and a corresponding code book in <code>data.table</code> format. For simplicity I am going to give 3 columns for both.</p>
  
  <pre><code>dt &lt;- data.table(id = 1:10,
                   a  = sample(c(1,2,3),10, replace = T),
                   b  = sample(c(1,2)  ,10, replace = T),
                   c  = sample(c(1:5)  ,10, replace = T))
  
      id a b c
   1:  1 2 1 2
   2:  2 2 1 1
   3:  3 3 1 1
   4:  4 3 1 1
   5:  5 1 2 5
   6:  6 2 1 3
   7:  7 1 2 3
   8:  8 1 1 2
   9:  9 2 1 5
  10: 10 3 2 4
  
  cb &lt;- data.table(var = c(rep("a", 3), rep("b", 2), rep("c", 5)),
                   val = c(1,2,3,1,2,1,2,3,4,5),
                   des = c("red", "blue", "yellow", "yes","no","K", "Na","Ag","Au","Si"))
  
      var val    des
   1:   a   1    red
   2:   a   2   blue
   3:   a   3 yellow
   4:   b   1    yes
   5:   b   2     no
   6:   c   1      K
   7:   c   2     Na
   8:   c   3     Ag
   9:   c   4     Au
  10:   c   5     Si
  </code></pre>
  
  <p>In <code>cb</code>, <code>var</code> is the corresponding variable in <code>dt</code>, and <code>val</code> is the value in <code>dt</code> that has the corresponding <code>des</code> value. I want to edit <code>dt</code> by replacing the values in <code>dt</code> by the values in <code>cb</code>. It should look like</p>
  
  <pre><code>    id      a   b  c
   1:  1    red yes Na
   2:  2 yellow  no Ag
   3:  3   blue yes Ag
   4:  4    red yes Au
   5:  5   blue yes Ag
   6:  6   blue  no Au
   7:  7 yellow yes Si
   8:  8   blue  no Ag
   9:  9    red  no  K
  10: 10 yellow  no Ag
  </code></pre>
  
  <p>How do I perform an operation like this efficiently and in a way that doesn't sound like my computer has built in piston?</p>
  
  <p>The reason is I have a pre-written code to analyze the data and need the actual values in order to run it. It may also prove useful in general because many times I am given data and a code book, but usually they aren't this many variables.</p>