I have data that looks like this:
A B C D
3 1 4 0.5
4 2 6 0.25
2 1 3 -0.4
3 3 6 -0.8
And I'd like to add a column E which is the result of either A divided by C or B divided by C based on if D < 0. I figured I should use apply in this situation but I don't really know how to work both a loop and an if statement into apply(). Any suggestions on how to tackle this?