【问题标题】:KDB: Create Empty Table Using Dynamic ColumnsKDB:使用动态列创建空表
【发布时间】:2018-08-21 19:45:06
【问题描述】:

我想创建一个包含以下静态列的空表: datesecurityactivehorizon

以及由以下变量表示的未定义数量的附加列: outFactor, subFacCols

outFactor 和 subFacCols 表示的列是浮点类型。如何创建包含上述列的虚拟表?

示例:

这些是前 5 列,不包括 subFacCols

dummyTable:flip (`date`security`active`horizon,outFactor)!(`date$();`int$();`boolean$();`int$();`float$())

【问题讨论】:

    标签: functional-programming formatting kdb


    【解决方案1】:

    您需要字典的键和值具有相同的长度,因此以下应该可以工作:

    q)outFactor:`price`size
    q)subFacCols:`bestBid
    q)dummyTable:flip (`date`security`active`horizon,outFactor,subFacCols)!(`date$();`int$();`boolean$();`int$()),(count[outFactor]#`float$()),count[subFacCols]#`float$()
    q)meta dummyTable
    c       | t f a
    --------| -----
    date    | d
    security| i
    active  | b
    horizon | i
    price   | f
    size    | f
    bestBid | f
    

    用途:https://code.kx.com/q/ref/lists/#take

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多