I have the following dataframe:
x income
1 46200
2 89345
3 189982
4 255465
5 301189
6 18100
7 55234
8 900672
9 108221
10 22201
I am attempting to apply a different function to each value depending on the range it lies within (e.g. 0-20k, 20-50k, 50-90k, 90-140k, & >140k). This function will look something like:
Average tax rate = ((Tax from prior marginal bracket + ((income - current bracket lower bound)*marginal rate))/income
I have attempted using a for loop with if & else if conditions however I'm having little success in applying this to my df, I'm not sure what my alternatives are in performing the required manipulation. I'm also unsure what R function would be best for such manipulation. Any help is greatly appreciated as R is new to me.
edit
Tax schedule & prior taxable amounts
Reproducible example:
Income = 60,000
Avgtax = ((6000 + ((60000 - 50000)*0.35))/60000
Avgtax = 15.83%