title: predict.lm() with an unknown factor level in test data
body: <p>I am fitting a model to factor data and predicting. If the <code>newdata</code> in <code>predict.lm()</code> contains a single factor level that is unknown to the model, <em>all</em> of <code>predict.lm()</code> fails and returns an error.</p>
  
  <p>Is there a good way to have <code>predict.lm()</code> return a prediction for those factor levels the model knows and NA for unknown factor levels, instead of only an error?</p>
  
  <p>Example code:</p>
  
  <pre><code>foo &lt;- data.frame(response=rnorm(3),predictor=as.factor(c("A","B","C")))
  model &lt;- lm(response~predictor,foo)
  foo.new &lt;- data.frame(predictor=as.factor(c("A","B","C","D")))
  predict(model,newdata=foo.new)
  </code></pre>
  
  <p>I would like the very last command to return three "real" predictions corresponding to factor levels "A", "B" and "C" and an <code>NA</code> corresponding to the unknown level "D".</p>