title: R - Convert and transpose data to columns by group
body: <p>I would greatly appreciate assistance from an R expert after struggling to solve this challenge for a few hours by trying tidyr, reshape, spread, etc.</p>
  
  <p>With a data frame of varying groups and assigned values, is there a way to convert and transpose the data frame such that each group is assigned to a new column and all of the assigned values are listed under the group?</p>
  
  <p>Here is some sample code for a data frame:</p>
  
  <pre><code>a &lt;- c("Group1", "Group1", "Group1", "Group2", "Group2", "Group2", "Group2", "Group2", "Group3")
  b &lt;- c("Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9") 
  </code></pre>
  
  <p>With these two columns, create a new column for each group. </p>
  
  <p>Below, I am showing this manually but would need R to automate this next step.</p>
  
  <p>I manually included "--" to avoid the error "Error in data.frame: arguments imply differing number of rows". In practice, I would not be able to add "--" for each group.</p>
  
  <pre><code>Group1 &lt;- c("Item1", "Item2", "Item3", "--", "--")
  Group2 &lt;- c("Item4", "Item5", "Item6", "Item7", "Item8")
  Group3 &lt;- c("Item9", "--", "--", "--", "--")
  </code></pre>
  
  <p>Below, this is the output that I am trying to create.</p>
  
  <pre><code>table &lt;- data.frame(Group1, Group2, Group3)
  </code></pre>
  
  <p>The challenge is that the variables have to be dynamic. The number of groups and number of items will change for different data sets, and I am unable to manually "--" for the blanks in each group.</p>
  
  <p>The question is similar to this one, except my question involves dynamic ranges.
  <a href="https://stackoverflow.com/questions/26498338/convert-data-frame-common-rows-to-columns/26498411">Convert data frame common rows to columns</a></p>