【发布时间】:2014-10-08 18:48:09
【问题描述】:
让我们有两个不重叠的 data.table 并进行滚动连接:
library(data.table)
P = data.table(id=c("a","a"), t=c(1,4), txn=c(0, 0),key=c("id", "t"))
TX = data.table(id=c("a"), t=c(3), txn=c(1111),key=c("id", "t")) # note the index t = 3 falling in the gap of P
P[TX, txn:=i.txn, roll=TRUE]
P
# id t txn
# 1: a 1 1111
# 2: a 4 0
为什么txn 会滚动到上一个 可用索引(t=1),而roll>0 我希望它会滚动到下一个 可用索引一个(t=4)?
P # expected
# id t txn
# 1: a 1 0
# 2: a 4 1111
【问题讨论】:
-
你想得到什么行为?或者你对此没意见,只是问为什么会这样?
-
@smci,他在帖子底部显示了预期的输出。
-
@Arun:我已经阅读了他写的内容。他没有说他是真的想要还是只是出于好奇。他没有说他想要什么。
标签: r data.table