title: Creating Binary Matrix in R with a large dataset
body: <p>I am working with R version 3.2.3 on a linux machine.</p>
  
  <p>I have a dataset with 1,374,439 observations of 145 variables. I need to transform this dataframe into a binary matrix.</p>
  
  <p>I have looked at different forums and I found a solution with the package reshape2 and the functions <code>melt()</code> and <code>dcast()</code>. This works perfectly with a small dataset (I always first tried my codes on a small parts in order to check if it is doing what I want). When I want to use this code on the whole dataset, it does not work anymore.</p>
  
  <p>I have looked at others forums and I have tried (with no success), the following functions:</p>
  
  <ul>
  <li><code>table()</code></li>
  <li><code>sparseMatrix()</code> and <code>as.Matrix()</code></li>
  <li><code>xtabs()</code></li>
  </ul>
  
  <p>I have also found the use of the packages dplyr and tidyr for bigger datasets. But I did not succeed. Honestly, I struggled with the understanding too. But it seems that the size of my dataset is the main problem...</p>
  
  <p>The data looks like that (this is a version short version):</p>
  
  <pre><code>    Code_1  Code_2  Code_3  Code_4  Code_5  Code_6  Code_7
  1   M201            M2187   M670
  2   O682            O097    Z370             O48    O759
  3   S7211   Z966            Z501
  </code></pre>
  
  <p>And I would like to have this (a binary matrix):</p>
  
  <pre><code>    M201    M2187   M670   O682   O097  Z370    O48   0759    S7211  Z966    Z501
  1   1          1       1      0      0     0      0      0        0     0       0
  2   0          0       0      1      1     1      1      1        0     0       0
  3   0          0       0      0      0     0      0      0        1     1       1
  </code></pre>
  
  <p>I would also like to be precise, that the blank spaces are not NAs. It is really blank spaces.</p>