title: Frequency table by group in data.table (R)
body: <p>I want to get for each group the frequencies of the values of a factor/categorial variable.</p>
  
  <p>The following does not work:</p>
  
  <pre><code>library(data.table)
  dt&lt;-data.table(fac=c("l1","l1","l2"),grp=c("A","B","B"))
  dt[,fac:=as.factor(fac)]
  dt[,list( table(fac) ),by=grp]
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code>Error in `[.data.table`(dt, , list(table(fac)), by = grp) : 
    All items in j=list(...) should be atomic vectors or lists. If you are trying something like j=list(.SD,newcol=mean(colA)) then use := by group instead (much quicker), or cbind or merge afterwards.
  </code></pre>
  
  <p>Is there an easy way to accomblish this task? Thanks.</p>