title: Converting from long to wide format
body: <p><a href="https://i.stack.imgur.com/LrRvb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LrRvb.jpg" alt="enter image description here"></a></p>
  
  <p>Want to transform the data from long format to wide format. Overall for ColA need to have only one row. There would be duplicates in ColB to ColE in those cases I am trying to aggregate it by count. ColF is aggregated by sum(). </p>
  
  <pre><code>s &lt;- read_csv("sample.csv")
  s_1 &lt;- subset(s, select=c("ColA", "ColF"))
  grp_by &lt;- aggregate(. ~ ColA , data = s_1, FUN = sum)
  head(grp_by)
  </code></pre>
  
  <p>Not sure how to transform the rest of the columns</p>
  
  <p><strong>Update:</strong> Based on the suggestion made use of reshape2 package</p>
  
  <pre><code>library(reshape2)
  
  s &lt;- read_csv("sample.csv")
  s_1 &lt;- subset(s, select=c("ColA", "ColF"))
  grp_by &lt;- aggregate(. ~ ColA , data = s_1, FUN = sum)
  
  s2 &lt;- dcast(s, ColA ~ ColB)
  s3 &lt;- dcast(s, ColA ~ ColC)
  s4 &lt;- dcast(s, ColA ~ ColD)
  s5 &lt;- dcast(s, ColA ~ ColE)
  
  print(s2)
  print(s3)
  print(s4)
  print(s5)
  print(grp_by)
  </code></pre>
  
  <p>This is the output of those print statements. </p>
  
  <p><a href="https://i.stack.imgur.com/4319Q.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4319Q.jpg" alt="enter image description here"></a></p>
  
  <p>How could I merge all those into one data frame? My actual dataset is 1 million records - Is this code optimal enough to run on top of it or is there better way of writing it. Thanks for all your help.</p>