title: How does one change the levels of a factor column in a data.table
body: <p>What is the correct way to change the levels of a <code>factor</code> column in a <code>data.table</code>  (note: not data frame) </p>
  
  <pre><code>  library(data.table)
    mydt &lt;- data.table(id=1:6, value=as.factor(c("A", "A", "B", "B", "B", "C")), key="id")
  
    mydt[, levels(value)]
    [1] "A" "B" "C"
  </code></pre>
  
  <p>I am looking for something like: </p>
  
  <pre><code>mydt[, levels(value) &lt;- c("X", "Y", "Z")]
  </code></pre>
  
  <p>But of course, the above line does not work. </p>
  
  <pre><code>    # Actual               # Expected result
      &gt; mydt                  &gt; mydt
         id value                id value
      1:  1     A             1:  1     X
      2:  2     A             2:  2     X
      3:  3     B             3:  3     Y
      4:  4     B             4:  4     Y
      5:  5     B             5:  5     Y
      6:  6     C             6:  6     Z
  </code></pre>