title: How to use the names_to argument in pivot_longer()
body: <p>I've seen a couple of other similar questions here on SO on the names_to argument; however, I'm still not sure I understand how to use it.</p>
  <p>Consider the below df:</p>
  <pre><code>df &lt;- data.frame(&quot;Metric&quot; = c(&quot;a_exp_2001&quot;,&quot;a_inc_2001&quot;,&quot;a_inc_2002&quot;,&quot;a_exp_2002&quot;),
                  &quot;John&quot; = c(220,230,240,250),
                  &quot;Abby&quot; = c(440,450,470,480))
  
  head(df)
  
        Metric John Abby
  1 a_exp_2001  220  440
  2 a_inc_2001  230  450
  3 a_inc_2002  240  470
  4 a_exp_2002  250  480
  </code></pre>
  <p>I'm looking to create a new data frame that has the above information for only one year (say 2002) but in long format. That is, I want to end up with 3 columns &quot;Names&quot;,&quot;Expenditure&quot; (where values correspond to <code>a_exp_2002</code>),&quot;Income&quot; (where values correspond to <code>a_inc_2002</code>).</p>
  <p>I'm not sure how to specify the <code>names_to</code> argument in <code>pivot_longer()</code> to get to that final df.</p>
  <p>I've only been able to get so far:</p>
  <pre><code>df %&gt;% 
     pivot_longer(cols = -c(Metric), ...)
  </code></pre>