-1

我正在尝试将一些列添加到基于由唯一标识符拆分的滚动计算的大型 data.table 中。

基于等效于 data.table 中的 ddply(...,transform,...)我生成了以下语句:

alldefaults[,`:=`(.SD[,list(obsPaymentDownMax24m=rollapplyr(obsPaymentsDown,24,max,partial=TRUE) 
                       ,obsPaymentDownAvg24m=rollapplyr(obsPaymentsDown,24,mean,partial=TRUE)
                       ,obsPaymentDownMax12m=rollapplyr(obsPaymentsDown,12,max,partial=TRUE)
                       ,obsPaymentDownAvg12m=rollapplyr(obsPaymentsDown,12,mean,partial=TRUE))]),by=OriginalApplicationID]

它产生一个错误

Error in `[.data.table`(alldefaults, , `:=`(.SD[, list(obsPaymentDownMax24m = rollapplyr(obsPaymentsDown,  : 
  In `:=`(col1=val1, col2=val2, ...) form, all arguments must be named.

当我在没有:=命名函数的情况下运行它时,它运行良好,但它是一个新数据集,然后需要重新加入它。

在 .SD 中插入分配

alldefaults[,.SD[,`:=`(list(obsPaymentDownMax24m=rollapplyr(obsPaymentsDown,24,max,partial=TRUE) 
                        ,obsPaymentDownAvg24m=rollapplyr(obsPaymentsDown,24,mean,partial=TRUE)
                        ,obsPaymentDownMax12m=rollapplyr(obsPaymentsDown,12,max,partial=TRUE)
                        ,obsPaymentDownAvg12m=rollapplyr(obsPaymentsDown,12,mean,partial=TRUE)))],by=OriginalApplicationID]

产生此错误

Error in `[.data.table`(.SD, , `:=`(list(obsPaymentDownMax24m = rollapplyr(obsPaymentsDown,  : 
  .SD is locked. Using := in .SD's j is reserved for possible future use; a tortuously flexible way to modify by group. Use := in j directly to modify by group by reference.




是否有使我错过的更新工作的技巧?




PS - 不确定这是否是一个足够重要的问题,需要一个可重现的示例,因为它似乎主要面向语法,并且希望很容易指出该语句应该是什么。此外,如果有人建议再次加快速度,我将不胜感激!

4

1 回答 1

1

我猜(猜,因为问题没有很好的形成,这可能是你被否决的原因)你想要这样做:

alldefaults[,`:=`(obsPaymentDownMax24m=rollapplyr(obsPaymentsDown,24,max,partial=TRUE) 
                 ,obsPaymentDownAvg24m=rollapplyr(obsPaymentsDown,24,mean,partial=TRUE)
                 ,obsPaymentDownMax12m=rollapplyr(obsPaymentsDown,12,max,partial=TRUE)
                 ,obsPaymentDownAvg12m=rollapplyr(obsPaymentsDown,12,mean,partial=TRUE)),by=OriginalApplicationID]
于 2013-11-06T16:09:07.860 回答