[datatable-help] Data Table Subset Question

Bernstein, Elliot J EJBernstein at wellington.com
Wed Aug 16 22:44:48 CEST 2017


Is there a way to subset a data table by the result of a grouped aggregation without adding an interim column to the table? For example, if I want to select all rows for which the group mean value of x is less than 10, I can do the following:

data <- data.table(x = 1:20, g = rep(c("a", "b"), each = 10))
data[, mean.x := mean(x), by = .(g)]
data[mean.x < 10,]

But I'm not really interested in "mean.x". Can I do the same thing without adding it to the table?

Thanks.

- Elliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20170816/b27f6512/attachment.html>


More information about the datatable-help mailing list