The data table structure is this:
DT <- data.table(category = c("categ A","categ A","categ A","categ B","categ B"),
type = c("type 1","type 1","type 3","type 2", "type 1"))
category type
1: categ A type 1
2: categ A type 1
3: categ A type 3
4: categ B type 2
5: categ B type 1
The expected output is this:
category type1 type2 type3
categ A 2 0 1
categ B 0 1 1
Basically I need to summarize by category
and create the three columns specifying a filter for each - I need to be able to specify the column names manually, not generate the based on the data.
My (hopeful) try was this:
DT_new <- DT[, list(type1=.N[type=="type 1"],
type2=.N[type=="type 2"],
type3=.N[type=="type 3"]),
by='Date')
This produced some strange output. I know I can create three separate data tables and then merge them together, but maybe there is another way?