title: Pivot_longer column groups
body: <p>In this dataframe I need to <code>pivot_longer</code> the two column groups starting with <code>f</code>, with each group pivoted separately:</p>
  <pre><code>df &lt;- structure(list(bigr_1_2 = c(&quot;i_PNP 'm_VBB&quot;,NA, NA), 
                       bigr_2_3 = c(&quot;it_PNP 's_VBZ&quot;, &quot;'ve_VHB got_VVN&quot;, NA), 
                       bigr_3_4 = c(&quot;you_PNP know_VVB&quot;, &quot;it_PNP 's_VBZ&quot;, &quot;'ve_VHB got_VVN&quot;), 
                       f_bigr_1_2 = c(14010L, NA, NA), 
                       f_bigr_2_3 = c(31831L, 10089L, NA), 
                       f_bigr_3_4 = c(14157L, 31831L, 10089L),
                       f1 = c(1,2,3),
                       f2 = c(4,5,6),
                       f3 = c(7,8,9)), 
                  class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA, -3L))
  </code></pre>
  <p><strong>EDIT</strong>: This two-step pivoting does <strong>not</strong> work:</p>
  <pre><code>library(tidyr)
  df %&gt;%
    pivot_longer(cols = matches(&quot;^f_bigr&quot;), 
                        names_to = &quot;bigr&quot;, 
                        values_to = &quot;f_bigr&quot;) %&gt;%
    pivot_longer(cols = matches(&quot;^f\\d&quot;), 
                        names_to = &quot;w&quot;, 
                        values_to = &quot;f_w&quot;)
  </code></pre>
  <p>How can it be properly done, perhaps (but not necessariyl) in one step? I've experimented with <code>names_pattern</code> but have not come to terms. Any help?</p>
  <p>The expected outcome:</p>
  <pre><code>bigr_1_2     bigr_2_3        bigr_3_4           w      f_w     bigr   f_bigr
    &lt;chr&gt;        &lt;chr&gt;           &lt;chr&gt;            &lt;chr&gt;  &lt;dbl&gt;   &lt;chr&gt;   &lt;int&gt;
  1 i_PNP 'm_VBB it_PNP 's_VBZ   you_PNP know_VVB   f1   1   f_bigr_1_2  14010
  2 i_PNP 'm_VBB it_PNP 's_VBZ   you_PNP know_VVB   f2   4   f_bigr_2_3  31831
  3 i_PNP 'm_VBB it_PNP 's_VBZ   you_PNP know_VVB   f3   7   f_bigr_3_4  14157
  4 NA           've_VHB got_VVN it_PNP 's_VBZ      f1   2   f_bigr_1_2     NA
  5 NA           've_VHB got_VVN it_PNP 's_VBZ      f2   5   f_bigr_2_3  10089
  6 NA           've_VHB got_VVN it_PNP 's_VBZ      f3   8   f_bigr_3_4  31831
  7 NA           NA              've_VHB got_VVN    f1   3   f_bigr_1_2     NA
  8 NA           NA              've_VHB got_VVN    f2   6   f_bigr_2_3     NA
  9 NA           NA              've_VHB got_VVN    f3   9   f_bigr_3_4  10089
  </code></pre>