title: How to deal with too large vector size in lm with many-level factor as control
body: <p>I'm trying to fit a linear model with roughly 900,000 observations and just two explanatory variables. Yet, I additionally need to include a control variable that is a many-level factor variable (11,135 levels). The code for the regression looks like this:</p>
  <p><code>model1 &lt;- dep_var ~ expl_var_1 + expl_var_2 + factor(control_var), data=data</code></p>
  <p>However, R throws me the error &quot;Cannot allocate a vector of size 75.6 GB&quot;
  I'm well aware that this is due to the many-level factor variable, however, I need to include this variable as a control. Please note: this is not an ordered factor; it is simply an id without any order.</p>
  <p>I've tried to find a solution to this problem, but ran into problems:</p>
  <ul>
  <li>I looked into plm - but that doesn't work because while my control variable can be interpreted as an ID time doesn't play a role (and even if it did; there can be &gt;1 observation per ID per time)</li>
  <li>I looked into biglm but this fits better the case of big data and not many-level factor</li>
  </ul>
  <p>My questions:</p>
  <ol>
  <li>Is there a way to include a variable in the regression and leaving it out when assigning the outcome of the regression to model1? I'm really not interested at all in the coefficients per control variable factor level. I just need to control for it.</li>
  <li>If there isn't: can I efficiently split up my regression even if I cannot make sure that in each chunk there are all control variable factor levels present (that isn't feasible, because some levels just have 1 observation)?</li>
  </ol>
  <p>I'd appreciate any starting points for a solution and ideas where to look for a solution - currently I'm just stuck with my level of knowledge and understanding.</p>
  <p>Thanks in advance for your time, support, and patience.</p>