>stk.dquote[, .(SecuCode, TradingDay, ChangePCT)]
SecuCode TradingDay ChangePCT
1: 000001 2013-07-25 0.00511
2: 000002 2013-07-25 -0.00943
3: 000004 2013-07-25 -0.02275
4: 000005 2013-07-25 0.00447
5: 000006 2013-07-25 -0.00487
---
790536: 603699 2014-11-11 -0.04537
790537: 603766 2014-11-11 -0.08306
790538: 603806 2014-11-11 -0.03491
790539: 603988 2014-11-11 0.09540
790540: 603993 2014-11-11 0.02569
> stk.dquote[, .N, by=SecuCode]
SecuCode N
1: 000001 316
2: 000002 316
3: 000004 316
4: 000005 316
5: 000006 316
---
2568: 603988 6
2569: 601015 5
2570: 603019 4
2571: 603011 3
2572: 603088 1
I try to do sth on this data.table
stk.dquote[, Momentum_1M := rollsum(ChangePCT, 21, fill = NA, align =
"right"), by=SecuCode]
and i get
Error: k <= n is not TRUE
the number of some SecuCode in this data.table is less than 21. How can i sovle this, any help would be much appreciated..