R - How to sum objects in a column between an interval defined by conditions on another column

后端 未结 2 1575
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 10:04

This comes as an application to this question:Sum object in a column between an interval defined by another column

What I would like to know is how to adjust the answer

2条回答
  •  借酒劲吻你
    2021-01-28 10:30

    I would create a for loop that tests whether A[i] - A[i-1] meets your criteria.

    If that is true it adds b[i] to a sum variable and repeats its way through.

    Because i is just iterating through A[] it shouldn't count anything from B[] twice.

提交回复
热议问题