I am learning data.table. I have difficulty converting the dplyr join syntax. Can you please recommend the data.table equivalence for the following test cases?
setkey(dtOrder, ProductID)
(1-2)
# this will be literally what you wrote
dtProduct[dtOrder,
list(OrderID, ProductID, ProductName, Qty, Price, ExtPrice=Qty*Price),
nomatch = 0 # or omit this to get (2)
]
# but I think you'd be better off with this
dtProduct[dtOrder][, ExtPrice := Qty*Price][]
(3)
# you can again take the literal direction:
dtProduct[dtOrder][!is.na(ProductName)][,
list(OrderID, ProductID, ProductName, Qty)]
# but again I think you'd be better off with
dtOrder[!dtProduct]
(4-5)
dtProduct[dtOrder, nomatch = 0][,
list(OrderCount=.N, TotalQty=sum(Qty), TotalSales=sum(Qty*Price)),
by = list(ProductID, ProductName)][
order(-TotalSales)]