I have two datasets: one detailed weight dataset and the other, which should be a composite dataset. I am trying to create a composite dataset by joining a part and aggregation dataset, but it is not working properly.
Here is a sample code.
mytesta <- data.table(cola = c("a","b"), groupa = c(1,2))
And this is my desired result.
cola groupa weighta 1: a 1 85 2: b 2 55
What i tried to do
mytesta[mytestb, on = "groupa", weight_summary := sum(i.weighta), by = "groupa"]
The problem is that when by is used, the columns of the internal data.table disappear (for example, mytesta[mytestb, on = "groupa", .SD, by = "groupa"] ). Is there any way around this?
Naumz source share