我想在R的後續觀察中計算%diff,並將其按變量分組。例如,給定的數據集是這樣的: dt <- data.table(group=c(rep("A", 3), rep("B", 3)),
index=rep(1:3, 2),
val=1:6)
# group index val
# 1: A 1 1
# 2: A 2 2
# 3: A 3 3
我注意到其中類似下面的測試失敗一些奇怪的情況: x = <a function from some module, passed around some big application for a while>
mod = __import__(x.__module__)
x_ref = getattr(mod, x.__name__)
assert x_ref is x # Fails