R data.table通过聚合在已连接的列上执行

时间:2016-05-26 15:27:16

标签: r join data.table

我想对连接的结果进行聚合(x和i是键控的data.tables),而不实现整个结果。它类似于.EACHI尝试解析但是对于由连接添加的列。

D1 <- data.table(x = rnorm(1:100), i = sample(1:100, 100, replace = TRUE), k = sample(1:100, 100, replace = TRUE))
D2 <- data.table(x = rnorm(1:100), j = sample(1:100, 100, replace = TRUE), k = sample(1:100, 100, replace = TRUE))
setkey(D1, k)
setkey(D2, k)

我想在对i和j对的D1和D2的连接结果上加x,而不实现D1的结果[D2]

D1[D2, list(x = sum(x * i.x)), by = list(i, j), allow.cartesian = TRUE] ## Fails
D1[D2, allow.cartesian = TRUE][, list(x = sum(x * i.x)), by = list(i, j)] ## Is the result I want but uses up more memory

有办法做到这一点吗?如果没有,它将在未来的版本中实现吗?

0 个答案:

没有答案