title: Pivot_Longer to Create Multiple Combined Columns
body: <p>I have seen some possible discussion of my problem elsewhere but it either wasn't resolved or I could not fully understand if the answer applied, so I'm creating a new question.</p>
  <p>The following question in particular touches on this subject but is not resolved.
  <a href="https://stackoverflow.com/questions/58145833/gathering-wide-columns-into-multiple-long-columns-using-pivot-longer">Gathering wide columns into multiple long columns using pivot_longer</a></p>
  <p>Take the following sample data. As you can see there is a unique identifier variable, and then 8 other variables. Of the other 8, you can group them into two sets, gpa and percent_a. For each set there is a class, group, course, and dept value.</p>
  <p>In my actual data I have about 20 different sets, all with the same structure, the same four descriptors in each set.</p>
  <p>What I would like to do is perform a function similar to pivot_longer. Except instead of combining multiple columns into a set of key and value columns, each unique set in my data (class, group, course, dept) would be grouped into there own key/value columns.</p>
  <pre><code>set.seed(101)
  df &lt;- data.frame(
    id = 1:10,
    class_gpa = rnorm(10, 0, 1),
    course_gpa = rnorm(10, 0, 1),
    group_gpa = rnorm(10, 0, 1),
    dept_gpa = rnorm(10, 0, 1),
    class_percent_a = rnorm(10, 0, 1),
    course_percent_a = rnorm(10, 0, 1),
    group_percent_a = rnorm(10, 0, 1),
    dept_percent_a = rnorm(10, 0, 1)
  )
  
  </code></pre>
  <p>So in this example, lets say I group all of the gpa values into two columns (gpa_type, and gpa_value) and the percent_a values into two columns (percent_a_type, percent_a_value), then I would end up at the end with only 5 columns:</p>
  <pre class="lang-r prettyprint-override"><code>id, gpa_type, gpa_value, percent_a_type, percent_a_value
  </code></pre>
  <p>Is there a way to do this? Either with pivot_longer or another method. Thanks.</p>