Joining data.table with by argument
问题 I have two data.table dx and dy dx <- data.table(a = c(1,1,1,1,2,2), b = 3:8) dy <- data.table(a = c(1,1,2), c = 7:9) I want to join dy to each row of dx , and below is the desired output data.table(plyr::ddply(dx, c("a", "b"), function(d) merge(d, dy, by = "a"))) a b c 1: 1 3 7 2: 1 3 8 3: 1 4 7 4: 1 4 8 5: 1 5 7 6: 1 5 8 7: 1 6 7 8: 1 6 8 9: 2 7 9 10: 2 8 9 However, I failed to make the output only using operation inside [] of data.table or merge ? I have tired merge(dx, dy, by = "a", all =