title: tidyr reshape tibble without expand.grid
body: <p>I'd like to reshape a tibble without using expand.grid. While expand.grid + delete missing obs + delete "flipped duplicates" (i.e a,b is the same as b,a) shall work, it would be quite slow to compute provided the many combinations I have.</p>
  
  <p>This is a dummy version of what I want to achieve:</p>
  
  <pre><code>library(dplyr)
  library(tidyr)
  
  initial_data &lt;- tibble(x = c("east","east","east"), y = c("a","b","c"), z = c(0.1,0.2,0.3))
  
  &gt; initial_data
  # A tibble: 3 x 3
        x     y     z
    &lt;chr&gt; &lt;chr&gt; &lt;dbl&gt;
  1  east     a   0.1
  2  east     b   0.2
  3  east     c   0.3
  
  final_data &lt;- tibble(x = c("east","east","east"), y1 = c("a","a","b"), y2 = c("b","c","c"), z1 = c(0.1,0.1,0.2), z2 = c(0.2,0.3,0.3))
  
  &gt; final_data
  # A tibble: 3 x 5
        x    y1    y2    z1    z2
    &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1  east     a     b   0.1   0.2
  2  east     a     c   0.1   0.3
  3  east     b     c   0.2   0.3
  </code></pre>
  
  <p>This works but is extremely inefficient:</p>
  
  <pre><code>expand_data &lt;- as_tibble(expand.grid(initial_data$x, initial_data$y, initial_data$y)) %&gt;% 
    filter(Var2 != Var3) %&gt;% 
    distinct()
  
  index &lt;- !duplicated(t(apply(expand_data, 1, sort)))
  expand_data &lt;- expand_data[index, ] %&gt;% 
    left_join(initial_data, by = c("Var1" = "x", "Var2" = "y")) %&gt;% 
    left_join(initial_data, by = c("Var1" = "x", "Var3" = "y"))
  
  &gt; expand_data
  # A tibble: 3 x 5
     Var1  Var2  Var3   z.x   z.y
    &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;
  1  east     b     a   0.2   0.1
  2  east     c     a   0.3   0.1
  3  east     c     b   0.3   0.2
  </code></pre>
  
  <p>Many thanks in advance !!</p>