long to wide format aggregate R tidyverse : <p>Hi given the following dataframe</p>

<pre><code>library(tidyverse)

df &lt;- data.frame(READS=rep(c('READa', 'READb', 'READc'),each=3) ,GENE=rep(c('GENEa', 'GENEb', 'GENEc'), each=3), COMMENT=rep(c('CommentA', 'CommentA', 'CommentA'),each=3))
&gt; df
  READS  GENE  COMMENT
1 READa GENEa CommentA
2 READa GENEa CommentA
3 READa GENEa CommentA
4 READb GENEb CommentA
5 READb GENEb CommentA
6 READb GENEb CommentA
7 READc GENEc CommentA
8 READc GENEc CommentA
9 READc GENEc CommentA
</code></pre>

<p>I want to convert from long to wide format aggregating by Gene Column so that i get the following</p>

<pre><code>         GENEa   GENEb  GENEc
READSa     3        3     3 
READSb     3        3     3
</code></pre>

<p>I have tried with no success:</p>

<pre><code> library(tidyverse)
      df %&gt;% 
      group_by(GENE) %&gt;% 
      select(-COMMENT) %&gt;%
      spread(READS) 
</code></pre>

<p>Note that the original dataframe is huge so any optimized code would help.</p>

<p>Thanks for your help.</p>
