[datatable-help] Expressions in "by" criteria (again)

Mike Sandfort cute_moniker at yahoo.com
Fri Jul 2 18:07:22 CEST 2010


Hi,

I suspect my question is similar to Harish's "Question #2" from 6/18. Suppose
I have a data.table with many fields and have a large subset of fields I need to include
in several expressions. Ordinarily, I would create (once) a vector of names of the fields
in my subset:
my.fields <- c("Apples","Bananas","Coconuts","Dragonfruits",...,"Pomelos")
    [where the whole data frame has many more fields, including "Broccoli","Cabbages",...]

Then I can re-use the my.fields vector when extracting subsets, creating plots, aggregating with
ddply(), etc. The problem is that I can't figure out how to (re)use my.fields to aggregate a
data.table.

DT[,sum(NumericField),by=(Apples,Bananas,Coconuts,Dragonfruits,...,Pomelos)] will work.
However,
DT[,sum(NumericField),by=my.fields]
won't work, nor will any combination of paste(), list(), eval(), quote(), deparse(), etc. applied
to my.fields (at least I haven't found one yet).

I know this is probably more an R-language issue, but since it's come up in my work with
the (excellent) data.table package, I thought I would ask here.

Thanks!
Mike S.


      


More information about the datatable-help mailing list