title: From long to wide data with multiple columns
body: <p>Suggestions for how to smoothly get from foo to foo2 (preferably with tidyr or reshape2 packages)?</p>
  
  <p>This is kind of like <a href="https://stackoverflow.com/questions/36207623/reformat-data-from-long-to-wide">this question</a>, but not exactly I think, because I don't want to auto-number columns, just widen multiple columns.  It's also kind of like <a href="https://stackoverflow.com/questions/10589693/convert-data-from-long-format-to-wide-format-with-multiple-measure-columns">this question</a>, but again, I don't think I want the columns to vary with a row value as in that answer.  Or, a valid answer to this question is to convince me it's exactly like one of the others.  The solution in the second question of "two dcasts plus a merge" is the most attractive right now, because it is comprehensible to me.</p>
  
  <p>foo:</p>
  
  <pre><code>foo = data.frame(group=c('a', 'a', 'b', 'b', 'c', 'c'),
                    times=c('before', 'after', 'before', 'after', 'before', 'after'),
                    action_rate=c(0.1,0.15, 0.2, 0.18,0.3, 0.35),
                    num_users=c(100, 100, 200, 200, 300, 300))
  foo &lt;- transform(foo,
                   action_rate_c95 = 1.95 * sqrt(action_rate*(1-action_rate)/num_users))
  
  &gt; foo
    group  times action_rate num_users action_rate_c95
  1     a before        0.10       100      0.05850000
  2     a  after        0.15       100      0.06962893
  3     b before        0.20       200      0.05515433
  4     b  after        0.18       200      0.05297400
  5     c before        0.30       300      0.05159215
  6     c  after        0.35       300      0.05369881
  </code></pre>
  
  <p>foo2:</p>
  
  <pre><code>foo2 &lt;- data.frame(group=c('a', 'b', 'c'),
                     action_rate_before=c(0.1,0.2, 0.3),
                     action_rate_after=c(0.15, 0.18,0.35),
                     action_rate_c95_before=c(0.0585,0.055, 0.05159),
                     action_rate_c95_after=c(0.069, 0.0530,0.0537),
                     num_users=c(100, 200, 300))
  
  &gt; foo2
    group action_rate_before action_rate_after action_rate_c95_before
  1     a                0.1              0.15                 0.0585
  2     b                0.2              0.18                 0.0550
  3     c                0.3              0.35                 0.05159
    action_rate_c95_after num_users
  1                 0.0690       100
  2                 0.0530       200
  3                 0.0537       300
  </code></pre>
  
  <p><strong>EDIT</strong>: Now I'd probably try to do it with <a href="https://tidyr.tidyverse.org/reference/pivot_wider.html" rel="nofollow noreferrer">pivot_wider from tidyr</a>.</p>