title: Efficiently Load A Sparse Matrix in R
body: <p>I'm having trouble efficiently loading data into a sparse matrix format in R.</p>
  
  <p>Here is an (incomplete) example of my current strategy:</p>
  
  <pre><code>library(Matrix)
  a1=Matrix(0,5000,100000,sparse=T)
  for(i in 1:5000)
    a1[i,idxOfCols]=x
  </code></pre>
  
  <p>Where x is usually around length 20.  This is not efficient and eventually slows to a crawl.  I know there is a better way but wasn't sure how.  Suggestions?</p>