了解rleid行为,有条件地重置的和

时间:2017-06-08 15:06:17

标签: r data.table cumsum

这是apcpDW = setDT(apcpDW)[, RAIN := cumsum(wm), by = rleid(wday == 2)]

的输出
    timestamp           wm wday         RAIN
 1: 1998-01-01  0.000000000    5  0.000000000
 2: 1998-01-02  0.005644862    6  0.005644862
 3: 1998-01-03  1.580885557    7  1.586530419
 4: 1998-01-04  7.033152468    1  8.619682888
 5: 1998-01-05  8.254771325    2  8.254771325
 6: 1998-01-06  7.309265805    3  7.309265805
 7: 1998-01-07  8.914006707    4 16.223272512
 8: 1998-01-08 13.836810823    5 30.060083334
 9: 1998-01-09  5.516107500    6 35.576190834
10: 1998-01-10  0.201572931    7 35.777763765

为什么在wday 23之间不能继续运行总和?它会在2之前重置,然后在2之后重新重置。我需要更改哪些内容才能获得wm2到下一个1的总和? (即,wday 1将始终具有最大值,后续2将完全为wm,然后3将为2+3 ......等等)

0 个答案:

没有答案