0

I am looking for the data.table equivalent of the following SQL query:

select date, item, count(value) from dataset group by date, item

So far, what I've got is this:

dataset[, .SD, by = c("date", "item", "value")]

However, this is giving me the number of rows for each value. I'm not sure how to specify that I want the number of values for each item, for each date. How can I achieve this?

mixedbag99
  • 529
  • 1
  • 4
  • 17

1 Answers1

2

This should do it:

dataset[, .(Counts=.N), by = .(date,item)]

SatZ
  • 430
  • 5
  • 14