title: Big matrix to run glmnet()
body: <p>I am having a problem to run glmnet lasso with a wide data set. My data has N=50, but p > 49000, all factors. So to run glmnet i have to create a model.matrix, BUT i just run out of memory when i call model.matrix(formula, data), where formula = Class ~ .</p>
  
  <p>As a worked example i will generate a dataset:</p>
  
  <pre><code>data &lt;- matrix(rep(0,50*49000), nrow=50)
  for(i in 1:50) {
  x = rep(letters[2:8], 7000)
  y = sample(x=1:49000, size=49000)
  data[i,] &lt;- x[y]
  }
  
  data &lt;- as.data.frame(data)
  x = c(rep('A', 20), rep('B', 15), rep('C', 15))
  y = sample(x=1:50, size=50)
  class = x[y]
  data &lt;- cbind(data, class)
  </code></pre>
  
  <p>After that i tried to create a model.matrix to enter on glmnet. </p>
  
  <pre><code>  formula &lt;- as.formula(class ~ .)
    X = model.matrix(formula, data)
    model &lt;- cv.glmnet(X, class, standardize=FALSE, family='multinomial', alpha=1, nfolds=10)
  </code></pre>
  
  <p>In the last step (X = model.matrix ...) i run out of memory. What can i do?</p>