title: sum(.) on a factor column returns incorrect result
body: <p>I am in a strange fix here. I am using <code>data.table</code> for a very routine task, but there is something that I am not able to explain. I have figured out a way around the problem, but I think it is still important for me to understand what is going wrong here.</p>
  
  <p>This code will bring the data into workspace:</p>
  
  <pre><code>library(XML)
  library(data.table)
  theurl &lt;- "http://goo.gl/hOKW3a"
  tables &lt;- readHTMLTable(theurl)
  new.Res &lt;- data.table(tables[[2]][4:5][-(1:2),])
  suppressWarnings(names(new.Res) &lt;- c("Party","Cases"))
  </code></pre>
  
  <p>There are two columns here, <code>Party</code> and <code>Cases</code>. Both of which have the default class of <code>factor</code>. Although, <code>Cases</code> should be <code>numeric</code>. Ultimately, I just want the sum of <code>Cases</code> for each <code>Party</code>. So something like this should work:</p>
  
  <pre><code>new.Res[,sum(Cases), by=Party]
  </code></pre>
  
  <p>But this doesn't give the right answer. I thought that it'll work if I change the class of <code>Cases</code> from <code>factor</code> to <code>numeric</code>. So I tried the following:</p>
  
  <pre><code>new.Res[,Cases := as.numeric(Cases)]
  new.Res[,sum(Cases), by=Party]
  </code></pre>
  
  <p>But I got the same incorrect answer. I realized that the problem is happening in changing the class of <code>Cases</code> from <code>factor</code> to <code>numeric</code>. So I tried a different method, and it worked:</p>
  
  <p>Step1: Reinitialize the data:</p>
  
  <pre><code>theurl &lt;- "http://goo.gl/hOKW3a"
  tables &lt;- readHTMLTable(theurl)
  new.Res &lt;- data.table(tables[[2]][4:5][-(1:2),])
  suppressWarnings(names(new.Res) &lt;- c("Party","Cases"))
  </code></pre>
  
  <p>Step2: Use a different method to change the class from <code>factor</code> to <code>numeric</code>:</p>
  
  <pre><code>new.Res[,Cases := strtoi(Cases)]
  new.Res[,sum(Cases), by=Party]
  </code></pre>
  
  <p>This works fine! However, I am not sure what's wrong with the first two methods. What am I missing?</p>