title: Rownames for data.table in R for model.matrix
body: <p>I have a <code>data.table</code> <code>DT</code> and I want to run <code>model.matrix</code> on it.  Each row has a string ID, which is stored in the <code>ID</code> column of <code>DT</code>.  When I run <code>model.matrix</code> on <code>DT</code>, my formula excludes the <code>ID</code> column.  The problem is, <code>model.matrix</code> drops some rows because of NAs.  If I set the rownames of <code>DT</code> to the <code>ID</code> column, before calling <code>model.matrix</code>, then the final model matrix has rownames, and I'm all set.  Otherwise, I can't figure out what rows I end up with.  I'm setting the rownames with <code>rownames(DT) = DT$ID</code>.  However, when I try to add a new column to <code>DT</code>, I get a complaint about </p>
  
  <blockquote>
    <p>"Invalid .internal.selfref detected . . . At an earlier point, this
    data.table has been copied by R."</p>
  </blockquote>
  
  <p>So I'm wondering</p>
  
  <ol>
  <li>Is there a better way to set rownames for a <code>data.table</code></li>
  <li>Is there a better approach to solving this problem.</li>
  </ol>