How can I sum the ‘calls’ conditionally on another column ‘price’.
If price is 0, then I don’t want to sum the calls for a contract.
I tried the sumOver function in combination with ifelse, but no success
contract | category | calls | price | sum |
---|---|---|---|---|
1 | A | 20 | 37 | 80 |
B | 40 | 0 | 80 | |
C | 60 | 22 | 80 | |
2 | B | 40 | 17 | 45 |
C | 23 | 0 | 45 | |
D | 5 | 12 | 24 | |
3 | A | 19 | 19 | 24 |
B | 8 | 0 | 24 | |
4 | A | 31 | 14 | 53 |
B | 22 | 18 | 53 | |
C | 9 | 0 | 53 | |
5 | B | 15 | 10 | 46 |
C | 31 | 38 | 46 | |
D | 2 | 0 | 46 | |
6 | A | 8 | 29 | 18 |
B | 10 | 19 | 18 |