Trying to use .SD inside by in data.table
2
I'm trying to use the .SD to groupby inside a data.table to apply a function to a specific column. I'm gonna use iris dataset as an example. Lets say I want to know how many unique Sepal.Length there is by species. library(data.table) obj="Species" as.data.table(iris)[,length(unique(Sepal.Length)),by=.SD,.SDcols=obj] It is important that I can supply .SDcols as an object, since I'm doing it programmatically. I also would like to know if it is possible using data.table instead of aggregate and/or xtabs solution. Appreciate any help.
r data.table
share | improve this question
asked Jan 1 at 23:32
...