title: Creating a User-Item Matrix for Collaborative Filtering
body: <p>I am attempting to run a Collaborative Filtering (CF) algorithm on a "User-Item-Rating" data. My data is in a long format i.e. each row has data for a User rating a specific item. I need to convert this into a "User-Item" matrix before I can apply a CF algorithm on it.</p>
  
  <p>I am using the <code>spread</code> function from the <code>tidyr</code> package for this task. But given that I have more than 50k unique items, the resulting dataframe would be huge. R is unable to execute this (on my local machine) and throws up the "cannot allocate vector of size" error.</p>
  
  <p>What's the best way to deal with this? Some of the options I tried exploring, but was unable to get them to work:</p>
  
  <ul>
  <li>I was thinking if there is a way to return the output of spread call as a Sparse Matrix </li>
  <li>I also tried exploring if packages which implements CF such as <code>recommenderlab</code> has an option to deal with this. But I could not see any option for that.</li>
  </ul>
  
  <p>Any help will be greatly appreciated.</p>
  
  <p>Thanks!</p>