title: Trying to use .SD inside by in data.table
body: <p>I'm trying to use the <code>.SD</code> to groupby inside a <code>data.table</code> to apply a function to a specific column. I'm gonna use iris dataset as an example.</p>
  
  <p>Lets say I want to know how many unique <code>Sepal.Length</code> there is by species.</p>
  
  <pre><code>library(data.table)
  obj="Species"
  as.data.table(iris)[,length(unique(Sepal.Length)),by=.SD,.SDcols=obj]
  </code></pre>
  
  <p>It is important that I can supply <code>.SDcols</code> as an object, since I'm doing it programmatically. I also would like to know if it is possible using <code>data.table</code> instead of aggregate and/or xtabs solution.</p>
  
  <p>Appreciate any help.</p>