title: Summarize data.table by group
body: <p>I am working with a huge data table in R containing monthly measurements of temperature for multiple locations, taken by different sources.</p>
  
  <p>The dataset looks like this:</p>
  
  <pre><code>library(data.table)
  
  # Generate random data:
  loc &lt;- 1:10
  dates &lt;- seq(as.Date("2000-01-01"), as.Date("2004-12-31"), by="month")
  mods &lt;- c("A","B", "C", "D", "E")
  temp &lt;- runif(length(loc)*length(dates)*length(mods), min=0, max=30)
  df &lt;- data.table(expand.grid(Location=loc,Date=dates,Model=mods),Temperature=temp)
  </code></pre>
  
  <p>So basically, for location 1, I have measurements from january 2000 to december 2004 taken by model A. Then, I have measurements made by model B. And so on for models C, D and E. And then, so on for location 2 to location 10.</p>
  
  <p>What I need to do is, instead of having five different temperature measurements (from the models), to take the mean temperature for all the models.</p>
  
  <p>As a result, I would have, for each location and each date, not five but ONLY ONE temperature measurement (that would be a multi-model mean).</p>
  
  <p>I tried this:</p>
  
  <pre><code>df2 &lt;- df[, Mean:=mean(Temperature), by=list(Model, Location, Date)]
  </code></pre>
  
  <p>which didn't work as I expected. I would at least expect the resulting data table to be 1/5th the number of rows of the original table, since I am summarizing five measurements into a single one.</p>
  
  <p>What am I doing wrong?</p>