title: tidyr spread function generates sparse matrix when compact vector expected
body: <p>I'm learning dplyr, having come from plyr, and I want to generate (per group) columns (per interaction) from the output of xtabs.</p>
  
  <p>Short summary: I'm getting</p>
  
  <pre><code>A    B
  1    NA
  NA   2
  </code></pre>
  
  <p>when I wanted</p>
  
  <pre><code>A    B
  1    2
  </code></pre>
  
  <hr>
  
  <p>xtabs data looks like this:</p>
  
  <pre><code>&gt; xtabs(data=data.frame(P=c(F,T,F,T,F),A=c(F,F,T,T,T)))
         A
  P       FALSE TRUE
    FALSE     1    2
    TRUE      1    1
  </code></pre>
  
  <p>now <code>do(</code> wants it's data in data frames, like this:</p>
  
  <pre><code>&gt; xtabs(data=data.frame(P=c(F,T,F,T,F),A=c(F,F,T,T,T))) %&gt;% as.data.frame
        P     A Freq
  1 FALSE FALSE    1
  2  TRUE FALSE    1
  3 FALSE  TRUE    2
  4  TRUE  TRUE    1
  </code></pre>
  
  <p>Now I want a single row output with columns being the interaction of levels.  Here's what I'm looking for:</p>
  
  <pre><code>FALSE_FALSE TRUE_TRUE FALSE_TRUE TRUE_FALSE
            1         1          2          1
  </code></pre>
  
  <p>But instead I get </p>
  
  <pre><code>&gt; xtabs(data=data.frame(P=c(F,T,F,T,F),A=c(F,F,T,T,T))) %&gt;% 
      as.data.frame %&gt;% 
      unite(S,A,P) %&gt;% 
      spread(S,Freq)
    FALSE_FALSE FALSE_TRUE TRUE_FALSE TRUE_TRUE
  1           1         NA         NA        NA
  2          NA          1         NA        NA
  3          NA         NA          2        NA
  4          NA         NA         NA         1
  </code></pre>
  
  <p>I'm clearly misunderstanding something here.  I'm looking for the equivalent of reshape2's code here (using magrittr pipes for consistency):</p>
  
  <pre><code>&gt; xtabs(data=data.frame(P=c(F,T,F,T,F),A=c(F,F,T,T,T))) %&gt;% 
      as.data.frame %&gt;% # can be omitted. (safely??)
      melt %&gt;% 
      mutate(S=interaction(P,A),value=value) %&gt;% 
      dcast(NA~S)
  Using P, A as id variables
    NA FALSE.FALSE TRUE.FALSE FALSE.TRUE TRUE.TRUE
  1 NA           1          1          2         1
  </code></pre>
  
  <p>(note NA is used here because I don't have a grouping variable in this simplified example)</p>
  
  <hr>
  
  <p>Update - interestingly, adding a single grouping column seems to fix this - why does it synthesise (presumably from row_name) a grouping column without me telling it?</p>
  
  <pre><code>&gt; xtabs(data=data.frame(h="foo",P=c(F,T,F,T,F),A=c(F,F,T,T,T))) %&gt;% 
    as.data.frame %&gt;% 
    unite(S,A,P) %&gt;% 
    spread(S,Freq)
      h FALSE_FALSE FALSE_TRUE TRUE_FALSE TRUE_TRUE
  1 foo           1          1          2         1
  </code></pre>
  
  <p>This seems like a partial solution.</p>