title: Convert data from data.table to matrix efficiently (speed and memory)
body: <p>I have a ~20,000x20,000 data, how do i convert the from <code>data.table()</code> to a <code>matrix</code> efficiently in terms of speed and memory? </p>
  
  <p>I tried <code>m = as.matrix(dt)</code> but it takes very long with many warnings. <code>df = data.frame(dt)</code> takes very long and result in reaching memory limits as well.</p>
  
  <p>Is there any efficient way to do this? Or, simply a function in data.table which returns <code>dt</code> as as matrix form(as required to feed into a statistical model using the <code>glmnet</code> package)?</p>
  
  <p>Simply wrapping into as.matrix gives me below error:</p>
  
  <pre><code>x = as.matrix(dt)
  
  Error: cannot allocate vector of size 2.9 Gb
  In addition: Warning messages:
    1: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
    2: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
    3: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
    4: In unlist(X, recursive = FALSE, use.names = FALSE) : Reached total allocation of 8131Mb: see help(memory.size)
  </code></pre>
  
  <p><strong>My OS:</strong> I have 64 bit Windows7 and 8gb ram, my Windows task manager shows Rgui.exe taking up spaces more than 4gb before and were still fine though. </p>