我正在合并两个data.tables(版本1.9.4)
library(data.table)
dt1 <- data.table(
key1 = rep(c("A", "B"), each = 2),
key2 = c("apple", "orange", "kiwi", "mango"),
vals = 1:4
)
setkey(dt1, key1, key2)
dt2 <- data.table(
key_one = rep(rev(c("A", "B")), each = 3),
key_two = rev(c("apple", "orange", "kiwi", "mango", "fig", "lemon")),
more_vals = 20:15
)
setkey(dt2, key_one, key_two)
这可以按预期工作
dt1[dt2]
这会返回错误
merge(dt1, dt2)
Error in merge.data.table(dt1, dt2) :
A non-empty vector of column names for `by` is required.
我是否错误地使用合并?