title: Replace <NA> in a factor column
body: <p>I want to replace <code>&lt;NA&gt;</code> values in a factors column with a valid value. But I can not find a way. This example is only for demonstration. The original data comes from a foreign csv file I have to deal with.</p>
  
  <pre><code>df &lt;- data.frame(a=sample(0:10, size=10, replace=TRUE),
                   b=sample(20:30, size=10, replace=TRUE))
  df[df$a==0,'a'] &lt;- NA
  df$a &lt;- as.factor(df$a)
  </code></pre>
  
  <p>Could look like this</p>
  
  <pre><code>      a  b
  1     1 29
  2     2 23
  3     3 23
  4     3 22
  5     4 28
  6  &lt;NA&gt; 24
  7     2 21
  8     4 25
  9  &lt;NA&gt; 29
  10    3 24
  </code></pre>
  
  <p>Now I want to replace the <code>&lt;NA&gt;</code> values with a number.</p>
  
  <pre><code>df[is.na(df$a), 'a'] &lt;- 88
  In `[&lt;-.factor`(`*tmp*`, iseq, value = c(88, 88)) :
    invalid factor level, NA generated
  </code></pre>
  
  <p>I think I missed a fundamental R concept about factors. Am I?
  I can not understand why it doesn't work. I think <code>invalid factor level</code> means that <code>88</code> is not a valid level in that factor, right? So I have to tell the factor column that there is another level?</p>