本文介绍了使用rollends滚动数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在定义 rollends = FALSE 时,我无法使 roll = -Inf 正常工作。如果未设置滚动数或将其设置为 TRUE ,则可以看到预期的结果。我将不胜感激任何建议。

I'm having trouble getting roll=-Inf to work when defining rollends=FALSE. When rollends is not set or set to TRUE, I see the expected result. I would appreciate any suggestions.

library(data.table)

dt1 = data.table(Date=seq(from=as.Date("2013-01-03"),
                          to=as.Date("2013-06-27"), by="1 week"),
                 key="Date")[, ind:=.I]
dt2 = data.table(Date=seq(from=as.Date("2013-01-01"),
                          to=as.Date("2013-06-30"), by="1 day"),
                 key="Date")

我希望看到 2013-01-05 2013-06-26 填充在下面的输出中。

I would expect to see 2013-01-05 and 2013-06-26 populated in the output below.

dt1[dt2, roll=-Inf, rollends=FALSE]
           Date ind
  1: 2013-01-01  NA
  2: 2013-01-02  NA
  3: 2013-01-03   1
  4: 2013-01-04   2
  5: 2013-01-05  NA
 ---
177: 2013-06-26  NA
178: 2013-06-27  26
179: 2013-06-28  NA
180: 2013-06-29  NA
181: 2013-06-30  NA

此如果按预期工作,则 ind 数据会前滚,但不会超出 dt1 <$ c中定义的端点之外$ c> data.table 。

This is working as expected, the ind data is rolled forward but not outside of the endpoints defined in the dt1 data.table.

dt1[dt2, roll=-Inf]
           Date ind
  1: 2013-01-01   1
  2: 2013-01-02   1
  3: 2013-01-03   1
  4: 2013-01-04   2
  5: 2013-01-05   2
 ---
177: 2013-06-26  26
178: 2013-06-27  26
179: 2013-06-28  NA
180: 2013-06-29  NA
181: 2013-06-30  NA


推荐答案

您是对的。

更新:现在已在(提交980)。来自:

UPDATE : Now fixed in v1.8.11 (commit 980). From NEWS :

感谢这个伟大的问题!

这篇关于使用rollends滚动数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:36