R data.table aggregate by date and another variable

807 views Asked by At

I have a big data.table (about 1.8M observations on 57 variables). In the original data, there's one variable with date and time as character, which I successfully converted to POSIXct. A scaled-down version of my data could be downloaded from here.

In order to obtain daily totals, I can aggregate the $value by:

exampleDF[,list(value.sum=sum(value)),by=as.Date(dateTime)]

and even by:

exampleDF[,list(value.sum=sum(value)),by=month(as.Date(dateTime))]

What I haven't been able to do is to aggregate by dateTime and another variable:

exampleDF[,list(value.sum=sum(value)),by=c("category","place")]    #--This WORKS, but
exampleDF[,list(value.sum=sum(value)),by=c("category",as.Date("dateTime"))] #-- This doesn't work

I've tried many combinations using quotation marks, list, but haven't found the correct one, I'll appreciate your kind help on how to make it work.

0

There are 0 answers