title: Cast function doesn't work well with sum function
body: <p>I recently encountered a problem when I try to use cast function to summarize some variables by groups.</p>
  
  <p>The details is the following:</p>
  
  <p>dataframe</p>
  
  <pre><code>id  time    variable    value
  1   1   x1  5
  1   2   x1  3
  2   1   x1  6
  2   2   x1  2
  1   1   x2  6
  1   2   x2  5
  2   1   x2  1
  2   2   x2  4
  </code></pre>
  
  <p>The following code works very well:</p>
  
  <pre><code>subjmeans &lt;- cast(mdata, id~variable, mean)
  
  subjmeans
  
  id  x1  x2
  1   4   5.5
  2   4   2.5
  </code></pre>
  
  <p>But when I replace the mean function (built in the cast function) with "sum", i.e. cast(mdata, id~variable, sum)</p>
  
  <p>R reports the following error message:</p>
  
  <blockquote>
  <pre><code>Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
    arguments imply differing number of rows: 4, 0
  </code></pre>
  </blockquote>
  
  <p>I also tried other functions like "max","length", everything works except for "sum".</p>
  
  <p>This is super weird, especially given that the same code worked very well with "sum" last week.</p>
  
  <p>Best
  Xinghua</p>