【问题标题】:Count consecutive preceding elements in DolphinDB计算 DolphinDB 中的连续前面元素
【发布时间】:2022-01-19 07:35:44
【问题描述】:
Volume f Explanation
10 0 no volume before 10
7 0 no smaller volume before 7
13 2 Both 10 and 7 are smaller than 13
6 0 13 is larger than 6
4 0 6 is larger than 4
8 2 Both 6 and 4 are smaller than 8
7 0 8 is larger than 7
3 0 7 is larger than 3
4 1 3 is smaller than 4

如上表所示,我想在 DolphinDB 中根据体积获取 f 列。 假设当前卷为 t,期望输出 f 为满足以下条件的卷数:

  1. volume 列中有连续的元素小于 t
  2. 连续元素的最后一卷是前一卷 在 t 之前;

详细的计算原理在说明栏中有说明。

我尝试了 for-loop,但它不起作用。 DolphinDB 是否支持任何其他函数来获取结果?

【问题讨论】:

    标签: count dolphindb


    【解决方案1】:
    t = table(1..10 as volume) tmp = select volume, iif(deltas(volume)>0, rowNo(volume), NULL) as flag from t tmp.bfill!() select volume, cumrank(volume) from tmp context by flag
    

    【讨论】:

    • 请记住,Stack Overflow 不仅仅是为了解决眼前的问题,而是为了帮助未来的读者找到类似问题的解决方案,这需要了解底层代码。这对于我们社区的初学者和不熟悉语法的成员来说尤其重要。鉴于此,您能否edit 您的答案包括对您正在做什么的解释以及为什么您认为这是最好的方法?
    猜你喜欢
    • 2017-12-26
    • 1970-01-01
    • 2019-08-01
    • 2015-12-01
    • 1970-01-01
    • 2014-01-06
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多