title: Replace 0 in matrix with NA
body: <p>What is most efficient way to replace all zeros in matrix with NAs?</p>
  
  <p>What I do:</p>
  
  <pre><code>my_matrix[my_matrix==0] &lt;- NA
  </code></pre>
  
  <p>I need it for recommender system (<a href="http://cran.r-project.org/web/packages/recommenderlab/index.html" rel="nofollow">recommenderlab</a>). Filling NAs take same time as building recommender system.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>dim(my_matrix) ~ 500000x500</p>
  
  <p>Where zeros are ~90%.</p>