title: Recoding of huge matrix in R
body: <p>I have a huge matrix with with values 1, 2 or 3 ( and some NA). If the matrix is n x m then I have to recode to n x 3m with each value of orginal matrix correspond to 3 entries of new matrix. If value is x in old matrix then xth entry will be 1 and other two would be zeros (if NA all of them zero). </p>
  
  <pre><code>1, 3,  NA, 1
  </code></pre>
  
  <p>is recoded to </p>
  
  <pre><code>1 0 0 0 0 1 0 0 0 1 0 0
  </code></pre>
  
  <p>I.e.</p>
  
  <pre><code>1  = 1 0 0  
  3  = 0 0 1
  NA = 0 0 0
  1  = 1 0 0 
  </code></pre>
  
  <p>I have to do this efficiently in R because matrix is huge. What is most efficient way to do this?  The matrix is in a data.table. </p>