title: Widening a data frame by copying values from a conditionally-identified row into new columns
body: <p>I have a data set for a meta-analysis that contains pre-test data in a set of columns, post-test data in another set of columns, and one column for condition (i.e., treatment [Condition == 1] versus control [Condition == 0]). I need to widen this data set such that I create a new set of columns for control observations' pre-test data and post-test data which is placed alongside that of the original treatment data. These data are grouped by ID. This means that I need to conditionally copy only observations that are "control" into a set of columns alongside the "treatment" observations, but within each ID group.</p>
  
  <p>I know that's an obnoxious way to describe it, so here's an example of the data set I have:</p>
  
  <pre><code>data_before.df &lt;- data.frame(ID = c(1,1,1,2,2,2,3,3,3),
                           Condition = c(0,1,2,0,1,2,0,1,2),
                           Pre_M = c(1,2,3,4,5,6,7,8,9),
                           Post_M = c(90,80,70,60,50,40,30,20,10))
  data_before.df
  </code></pre>
  
  <p>And here's what I need to get to:</p>
  
  <pre><code>data_after.df &lt;- data.frame(ID = c(1,1,2,2,3,3),
                              Condition = c(1,2,1,2,1,2),
                              Pre_M = c(2,3,5,6,8,9),
                              Post_M = c(80,70,50,40,20,10),
                              Control_Pre_M = c(1,1,4,4,7,7),
                              Control_Post_M = c(90,90,60,60,30,30))
  data_after.df
  </code></pre>