title: R problems using table() with mdply
body: <p>I'd like to count the occurrences of elements per row of a data frame. I'm trying to use table together with mdply to do so. On my test data this works fine.</p>
  
  <pre><code>library(plyr)
  Data_frame_s1 &lt;- data.frame(Gene_symbol=c("geneA","geneB","geneC"), cell1=c("state_1", "state_2" ,"unclassified"))
  Data_frame_s2 &lt;- data.frame(Gene_symbol=c("geneA","geneB","geneC"), cell2=c("state_1", "state_2", "unclassified"))
  Data_frame_s3 &lt;- data.frame(Gene_symbol=c("geneA","geneB","geneC"), cell3=c("state_2", "unclassified", "unclassified"))
  Data_frame_s4 &lt;- data.frame(Gene_symbol=c("geneA","geneB","geneC"), cell4=c("unclassified", "unclassified", "unclassified"))
  temp = list(Data_frame_s1, Data_frame_s2, Data_frame_s3, Data_frame_s4)
  Data_frame &lt;- join_all(temp, by="Gene_symbol", type="full")
  add_table &lt;- function(row) {r = table(unname(unlist(row[-1])))}
  Data_frame &lt;- adply(Data_frame, 1, add_table)
  Data_frame
  </code></pre>
  
  <p>This gives me</p>
  
  <pre><code>  Gene_symbol        cell1        cell2        cell3        cell4 state_1
  1       geneA      state_1      state_1      state_2 unclassified       2
  2       geneB      state_2      state_2 unclassified unclassified       0
  3       geneC unclassified unclassified unclassified unclassified       0
    state_2 unclassified
  1       1            1
  2       2            2
  3       0            4
  </code></pre>
  
  <p>as desired.</p>
  
  <p>When I do the same on my real data, however, I get an error:</p>
  
  <pre><code>Error in list_to_dataframe(res, attr(.data, "split_labels"), .id, id_as_factor) : 
    Results do not have equal lengths
  Calls: adply -&gt; ldply -&gt; list_to_dataframe
  Execution halted
  </code></pre>
  
  <p>The strange thing is that I can work around this by saving my data to file, loading them back and then call mdply. So</p>
  
  <pre><code>Data_frame &lt;- join_all(temp, by="Gene_symbol", type="full")
  write.table(Data_frame, "test.txt")
  Data_frame &lt;- read.table("test.txt", header=TRUE)
  Data_frame &lt;- adply(Data_frame, 1, add_table)
  Data_frame
  </code></pre>
  
  <p>gives me the desired result for the real data.</p>
  
  <p>Does anybody have an explanation for this behaviour? I know the problem will be difficult to reproduce, but as I said I am unable to reproduce it myself with any test data and it does not even persist when I save and reload the data. But maybe someone has an idea from what I have described above.</p>