title: model.matrix() with na.action=NULL?
body: <p>I have a formula and a data frame, and I want to extract the <code>model.matrix()</code>. However, I need the resulting matrix to include the NAs that were found in the original dataset. If I were to use <code>model.frame()</code> to do this, I would simply pass it <code>na.action=NULL</code>. However, the output I need is of the <code>model.matrix()</code> format. Specifically, I need only the right-hand side variables, I need the output to be a matrix (not a data frame), and I need factors to be converted to a series of dummy variables. </p>
  
  <p>I'm sure I could hack something together using loops or something, but I was wondering if anyone could suggest a cleaner and more efficient workaround. Thanks a lot for your time!</p>
  
  <p>And here's an example:</p>
  
  <pre><code>dat &lt;- data.frame(matrix(rnorm(20),5,4), gl(5,2))
  dat[3,5] &lt;- NA
  names(dat) &lt;- c(letters[1:4], 'fact')
  ff &lt;- a ~ b + fact
  
  # This omits the row with a missing observation on the factor
  model.matrix(ff, dat) 
  
  # This keeps the NA, but it gives me a data frame and does not dichotomize the factor
  model.frame(ff, dat, na.action=NULL) 
  </code></pre>
  
  <p>Here is what I would like to obtain: </p>
  
  <pre><code>   (Intercept)          b fact2 fact3 fact4 fact5
  1            1  0.7266086     0     0     0     0
  2            1 -0.6088697     0     0     0     0
  3            NA 0.4643360     NA    NA    NA    NA
  4            1 -1.1666248     1     0     0     0
  5            1 -0.7577394     0     1     0     0
  6            1  0.7266086     0     1     0     0
  7            1 -0.6088697     0     0     1     0
  8            1  0.4643360     0     0     1     0
  9            1 -1.1666248     0     0     0     1
  10           1 -0.7577394     0     0     0     1
  </code></pre>