title: Pivot/gather multiple "crossed" values belonging to a common key
body: <p>I have some strangely stored time series data.  Two kinds of values, <code>event</code> and <code>foo</code>, can be observed together for different phenomena <code>a</code> and <code>b</code>.  The observations are in time <code>t</code> and belong to different <code>category</code> (those are basically different recordings).</p>
  <p>Everything is stored as follows, in a kind of mixed wide format:</p>
  <pre><code>&gt; tibble(category = c(&quot;x&quot;, &quot;x&quot;, &quot;y&quot;, &quot;y&quot;), t = c(1:2, 1:2),
    event_a = c(T, T, F, F), event_b = c(T, F, T, F), 
    foo_a = c(1, 2, 3, 4), foo_b = c(10, 20, 30, 40))
  
  # A tibble: 4 x 6
    category     t event_a event_b foo_a foo_b
    &lt;chr&gt;    &lt;int&gt; &lt;lgl&gt;   &lt;lgl&gt;   &lt;dbl&gt; &lt;dbl&gt;
  1 x            1 TRUE    TRUE        1    10
  2 x            2 TRUE    FALSE       2    20
  3 y            1 FALSE   TRUE        3    30
  4 y            2 FALSE   FALSE       4    40
  </code></pre>
  <p>Now I want convert it to long format, with the phenomena being used to index the kind of <code>event</code> with a <code>value</code>, and the <code>foo</code> value being matched to them via <code>a</code>/<code>b</code>:</p>
  <pre><code># A tibble: 8 x 5
    category     t event value   foo
    &lt;chr&gt;    &lt;dbl&gt; &lt;chr&gt; &lt;lgl&gt; &lt;dbl&gt;
  1 x            1 a     TRUE      1
  2 x            1 b     TRUE     10
  3 x            2 a     TRUE      2
  4 x            2 b     FALSE    20
  5 y            1 a     FALSE     3
  6 y            1 b     TRUE     30
  7 y            2 a     FALSE     4
  8 y            2 b     FALSE    40
  </code></pre>
  <p>I'm looking for some sort of <code>tidyr</code> (or at least <code>tidyverse</code>) solution using <code>gather</code>/<code>pivot_long</code> and friends, but couldn't come up with anything useful, since there are multiple value columns in the result.  I was thinking about a join with the <code>foo</code> columns split of, but didn't really succeed, and I'm not really enought in to SQL to know what goes wrong there...</p>