I would like to calculate the conditional sum of a column of a data frame for a set of intervals [n, +β)(i.e. β₯ n) applied to another column. In the examples below, the intervals are applied to the column a, and the values ββin the column are bconditionally summed. For [0, +β)all values ββof a column a β₯ 0, therefore b_sum- this is the sum of all values. For [3, +β)only one entry β₯ 3, therefore b_sumequal to 500.
Input data
a b
1.1 100
2.3 150
0.1 20
0.5 80
3.3 500
1.6 200
1.1 180
Desired Result
n b_sum
0 1230
1 1130
2 650
3 500
4 0
I am sure this would be easy enough using a loop for; But; I would like to avoid this approach and use an approach using a vectorized base Ror dplyr.