title: Pivoting population data with multible sex specific age groups
body: <p>I have the following population structure:</p>
  <pre><code>tibble(
    female = c(&quot;0-10&quot;, &quot;10-20&quot;),
    female_population = c(30000, 50000),
    male = c(&quot;0-10&quot;, &quot;10-20&quot;),
    male_population = c(33000, 45000),
    total = c(&quot;0-10&quot;, &quot;10-20&quot;),
    total_population = female_population + male_population
  )
  
  # A tibble: 2 x 6
    female female_population male  male_population total total_population
    &lt;chr&gt;              &lt;dbl&gt; &lt;chr&gt;           &lt;dbl&gt; &lt;chr&gt;            &lt;dbl&gt;
  1 0-10               30000 0-10            33000 0-10             63000
  2 10-20              50000 10-20           45000 10-20            95000
  </code></pre>
  <p>I'd like to pivot it so that I get a single column for age, sex and population like this:</p>
  <pre><code>tibble(
    sex = rep(c(&quot;female&quot;, &quot;male&quot;, &quot;total&quot;), each = 2),
    age = rep(c(&quot;0-10&quot;, &quot;10-20&quot;), 3),
    population = c(30000, 50000, 33000, 45000, 63000, 95000)
  )
  
  # A tibble: 6 x 3
    sex    age   population
    &lt;chr&gt;  &lt;chr&gt;      &lt;dbl&gt;
  1 female 0-10       30000
  2 female 10-20      50000
  3 male   0-10       33000
  4 male   10-20      45000
  5 total  0-10       63000
  6 total  10-20      95000
  </code></pre>
  <p>Any ideas how to do that elegantly, maybe using pivot_longer?</p>