title: How do I pivot pairs of columns in R?
body: <p>I'm having difficulty pivotting paired columns. I understand there is the <code>names_pattern</code> argument and I cannot figure out how to make this work.</p>
  <p>My data looks like this:</p>
  <pre><code>structure(list(Q8_1_avg = 4.72562264837839, Q8_1_avg_se = 0.0595342202500642, 
                 Q8_1_unweighted = 4.90473815461347, Q8_2_avg = 4.65508494735021, 
                 Q8_2_avg_se = 0.0541589332376175, Q8_2_unweighted = 4.6498753117207, 
                 Q8_3_avg = 5.4756060523178, Q8_3_avg_se = 0.0534895224170486, 
                 Q8_3_unweighted = 5.57506234413965), row.names = c(NA, -1L
                 ), class = &quot;data.frame&quot;)-&gt;dat
  
  
  </code></pre>
  <p>And my desired output looks like this:</p>
  <pre><code>df&lt;-data.frame(
  Question=c('Q8_1', 'Q8_2','Q8_3'),
  #Values taken from Q8_[123]_avg
  Weighted_Average=c(4.72,4.65, 5.47),
  #Values taken from Q8_[123]_avg_se
  Weighted_SE=c(0.05,0.05 ,0.05),
  #Values taken from Q8_[123]_unweighted
  Unweighted_Average=c(4.90, 4.64, 5.57)
  )
  df
  </code></pre>
  <p>Thank you for any assistance.</p>