I have two data tables MP and MK as shown below. I tried merging but I am getting wrong results! I know it can be done with a couple of for loops, but I am looking for some elegant way in data table for this, as the actual data table I have is huge(~100,000 rows) Can someone please help me join these two data tables to get the final result as shown below.
MP <- data.table(
M = c("m1","m1","m1","m2","m2", "m1"),
P = c("p1","p2","p4","p1","p3", "p1")
)
MK <- data.table(
M = c("m1","m1","m2"),
K = c("k1","k2","k1")
)
FINAL EXPECTED RESULT
M P K
m1 p1 k1
m1 p1 k2
m1 p2 k1
m1 p2 k2
m1 p4 k1
m1 p4 k2
m2 p1 k1
m2 p3 k1