title: How to convert dataframe into sparse matrix?
body: <p>How to convert dataframe into sparse matrix? 
  For example, please see below the <code>dataframe</code>. Need to see this <code>dataframe</code> as a whole factor with levels 1~10. Convert levels into 10 columns. Convert 0 to 1 based on what factor it has it each Row in V1~V4. Which will become something like the <code>Expected Outcome</code>. </p>
  
  <p>Take Row 1 in <code>Expected Outcome</code> for example, column <code>No1</code>, <code>No2</code>, <code>No5</code>, <code>No8</code> == 1 because V1~V4 has the number 1,8,2,5.</p>
  
  <p><strong>Update:</strong> Have tried solution <a href="https://stackoverflow.com/questions/26207850/create-sparse-matrix-from-a-data-frame/26208307#26208307">Create Sparse Matrix from a data frame</a>  , cannot get it to match my <code>Expected Outcome</code></p>
  
  <p><strong>Dataframe</strong> </p>
  
  <pre><code>    V1   V2   V3   V4  
  1   1    8    2    5
  2   6    7    9    3
  3   6    2    3    2
  4   5    8    9    10
  5   4    3    5    1
  6   3    9    1    10
  </code></pre>
  
  <p><strong>Expected Outcome</strong></p>
  
  <pre><code>    V1   V2   V3   V4   No1 No2 No3 No4 No5 No6 No7 No8 No9 No10 
  1   1    8    2    5     1   1   0   0   1   0   0   1   0   0
  2   6    7    9    3     0   0   1   0   0   1   1   0   1   0
  3   6    2    3    4     0   1   1   1   0   1   0   0   0   0  
  4   5    8    9    10    0   0   0   0   1   0   0   1   1   1
  5   4    3    5    1     1   0   1   1   1   0   0   0   0   0
  6   3    9    1    10    1   0   1   0   0   0   0   0   1   1
  </code></pre>