title: r tidyverse spread() using multiple key value pairs not collapsing rows
body: <p>I am trying to spread() a couple of key/value pairs but the common value column does not collapse. I think that it may have to do with some previous processing, or more likely I do not know the right way to spread two or more key/value pairs to get the result I expect.</p>
  
  <p>I'm starting with this data set:</p>
  
  <pre><code>library(tidyverse)
  
  df &lt;- tibble(order = 1:7,
               line_1 = c(23,8,21,45,68,31,24),
               line_2 = c(63,25,25,24,48,24,63),
               line_3 = c(62,12,10,56,67,25,35))
  </code></pre>
  
  <p>There are 2 pre-spread steps to define order of the "count" values created in the following gather() function. This is the first pre-spread step to define the original order of the "count" variable using the row number:</p>
  
  <pre><code>ntrl &lt;- df %&gt;%
             gather(line_1,
                    line_2,
                    line_3,
                    key = "sector",
                    value = "count") %&gt;%
             group_by(order) %&gt;%
             mutate(sector_ord = row_number()) %&gt;%
             arrange(order,
                     sector)
  </code></pre>
  
  <p>This is the second pre-spread step to define the numerical order of the "count" variable:</p>
  
  <pre><code>ord &lt;- ntrl %&gt;%
              arrange(order,
                      count) %&gt;%
              group_by(order) %&gt;%
              mutate(num_ord = paste0("ord_",
                                      row_number(),
                                      sep=""))
  </code></pre>
  
  <p>And then finally the spread code that I have been using:</p>
  
  <pre><code>wide &lt;- ord %&gt;%
              group_by(order) %&gt;%
              spread(key = sector,
                     value = count) %&gt;%
              spread(key = num_ord,
                     value = sector_ord)
  </code></pre>
  
  <p>What I'm getting is this:</p>
  
  <pre><code>    order   line_1  line_2  line_3  ord_1   ord_2   ord_3                           
  1   1       23      NA      NA      1       NA      NA
  2   1       NA      63      NA      NA      NA      2
  3   1       NA      NA      62      NA      3       NA
  4   2       8       NA      NA      1       NA      NA
  5   2       NA      25      NA      NA      NA      2
  6   2       NA      NA      12      NA      3       NA
  7   3       21      NA      NA      NA      1       NA
  8   3       NA      25      NA      NA      NA      2
  9   3       NA      NA      10      3       NA      NA
  ... and so on thru 21 lines accounting for all 7 "order" lines
  </code></pre>
  
  <p>The behavior that I am expecting is that the "order" column would collapse in all rows that are the same "order" value to give the following:</p>
  
  <pre><code>    order   line_1  line_2  line_3  ord_1   ord_2   ord_3                           
  1   1       23      63      62      1       3       2
  2   2       8       25      12      1       3       2
  3   3       21      25      10      2       3       1
  4   4       45      24      56      2       1       3
  ... and so on, I think that paints the picture
  </code></pre>
  
  <p>I have reviewed the questions and answers about spreading with duplicate identifiers and the use of the index of row numbers but that does not help. </p>
  
  <p>I figure that it has something to do with the double spreading, but I cannot figure out how to do that.</p>
  
  <p>Thanks for your help.</p>