How can I build a compact matrix from a sparse dataframe?
<p>I have a dataframe containing three columns 1st: origin interactor (org), 2nd: value of interaction (rsq) 3rd: target interactor(tgt), which look like this (example) <a href="http://i.stack.imgur.com/9yIBU.png" rel="nofollow">enter image description here</a>, i would like to convert it into a compact matrix like this(example)<a href="http://i.stack.imgur.com/WU6LB.png" rel="nofollow">enter image description here</a>, the dataframe that I am using is really big, (36791 elements) in order to do that, I coded the following:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>the_list  &lt;- data.frame(org,rsq,tgt)

a  &lt;- length(org)
b  &lt;- length(tgt)

str(the_list)
#output matrix
dm = matrix( nrow= a, ncol= b, dim = list(org, tgt))

for (i in 1:nrow(the_list)){ #iterate thorugh lines of input file
  
  dm[match(the_list[i,1],rownames(dm)), match(the_list[i,3],colnames(dm))] = the_list[i,2]
                                                      
}
dm</code></pre>
</div>
</div>

I would really appreciate your support in that, since, as you might guess, I have basically no experience in that.
Thank you so much
Alfredo</p>