title: Replace NAs in a Single Column of a Data Table in R
body: <p>I'm trying to replace NAs in a single column of a datatable in R with "-999" and I can quite get it.</p>
  
  <p>There is related question <a href="https://stackoverflow.com/questions/7235657/fastest-way-to-replace-nas-in-a-large-data-table">here</a> on Stackoverflow but I think this can be done without iterating through the table.</p>
  
  <p>I have a column, <code>column_to_check</code> in a datatable.  The column is a factor variable and has 80K observations consisting of NA, 0, and 1.  I'm trying to change the <code>NA</code> to <code>-999</code> so I can do further work.</p>
  
  <p>The code I'm working with is this:</p>
  
  <pre><code>is.na(DT[,column_to_check,with=FALSE]) = "-999"
  </code></pre>
  
  <p>and </p>
  
  <pre><code>DT[is.na(column_to_check), column_to_check:="-999"]
  </code></pre>
  
  <p>The first line sets the entire column to NA.  The second doesn't work and I know is off but I think I'm close.</p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks.</p>