【发布时间】:2021-01-24 01:48:29
【问题描述】:
根据表t 中的一些数据和整数p 和q,对函数fx 的每次调用都会向x 左连接一个新列。
我在下面的 p 和 q 的值上显示了所需的迭代,但不知道如何使用 KDB+ 迭代器正确地进行迭代。
示例数据和解决方案:
x:([]date:(2013.07.01+til 10);ords:til 10); /Some random table with date (key column)
t:p:([]date:(2013.07.01+1000#til 200);px:1000?10e); /Some random table.
fx:{[x;t;p;q]
/Do something with t;p;q and left-join output column to x on date;
t:([]date:(2013.07.01+til 10);ords:10?10000);
col_names:(`date;`$""sv(string(`P);string(p);string(`Q);string(q)));
t: x lj 1!col_names xcol t;
:t
};
/Run simulation for p=1 to 2 and q=3 to 4 as follows:
fx[ fx[ fx[ fx[x;t;1;3]; t;2;3]; t;1;4]; t;2;4] /How to do this iteration properly?
最后一条语句在 p 和 q 上有两个 for 循环,分别来自 1to2 和 3to4。我确信有更好的方法可以使用扫描/覆盖来实现这一点,但我无法弄清楚。有人可以在这里帮忙吗。
【问题讨论】:
标签: iterator simulation kdb