title: R- model.matrix for factors returning all levels
body: <p>I need to predict probabilities manually. I'm working using <a href="https://stackoverflow.com/questions/25695565/predict-with-arbitrary-coefficients-in-r">this post code</a>.
  I wanted to delete a variable from a model and keep the original coefficients to predict another period.
  My formula is:</p>
  
  <pre><code>&gt; lr$formula
  target ~ grupoAntig + nu_seguros_1TRUNC + cd_sexo + grupoEdad + 
      vl_limite_aeQU + vl_ltd_6QU + Revolv3 + nu_servicios_1TRUNC + 
      fl_cliente_hit + nu_resumen_6 + fl_rv
  </code></pre>
  
  <p>I want to delete  fl_cliente_hit. So I'm using model.matrix and excluding it:</p>
  
  <pre><code>mm&lt;-model.matrix(~ grupoAntig + nu_seguros_1TRUNC + cd_sexo + grupoEdad + 
      vl_limite_aeQU + vl_ltd_6QU + Revolv3 + nu_servicios_1TRUNC + 
       nu_resumen_6 + fl_rv, train)[,]
  </code></pre>
  
  <p>So the first line of this matrix is:</p>
  
  <pre><code>&gt; mm[1,]
          (Intercept)       grupoAntigh20       grupoAntigm40 
                    1                   0                   1 
    nu_seguros_1TRUNC            cd_sexoF            cd_sexoM 
                    0                   0                   1 
         grupoEdadh25        grupoEdadm40   vl_limite_aeQU145 
                    0                   1                   0 
          vl_ltd_6QU5             Revolv3 nu_servicios_1TRUNC 
                    0                   0                   0 
         nu_resumen_6              fl_rv1 
                    4                   0 
  </code></pre>
  
  <p>I guess this should keep (number of levels-1) levels of the variable. For example:</p>
  
  <pre><code>&gt; ddply(train, .(grupoEdad  ), summarize, cant=length(target))
    grupoEdad  cant
  1     25a40  7864
  2       h25    60
  3       m40 11684 
  </code></pre>
  
  <p>And the matrix only includes 2 of those 3 levels as you can see in mm[1,]</p>
  
  <p>But the problems is for cd_sexo:</p>
  
  <pre><code>&gt; ddply(train, .(cd_sexo), summarize, cant=length(target))
    cd_sexo  cant
  1       F  8962
  2       M 10646
  </code></pre>
  
  <p>It only has 2 levels and it's including both.</p>
  
  <p>My problem is that since I want to predict probabilities I will use coeff(lr) and I will have different number of variables compared to mm matrix.</p>