I use the following code to calculate tax using R. where two variable can be given as argument . When a data set is used i want to calculate tax based on the category. I am new to package development. Kindly help me solve this problem.
I get error when i insert a dataset only the first category is calculated and get this Waring message.
Warning message: In if (category == 1) { : the condition has length > 1 and only the first element will be used
IIT<- function(income,category) {
if (category == 1){
if (income > 0 && income <= 18200) {
tax <- 0
} else if (income > 18200 && income <= 37000) {
tax <- (income - 18200) * .10
} else if (income > 37000 && income <= 80000) {
tax <- 3572 + (income - 37000) * .20
} else if (income > 80000 && income <= 180000) {
tax <- 17547 + (income - 80000) * .30
} else if (income > 180000 && Inf) {
tax <- 54547 + (income - 180000) * .40
}
return(tax)}
else if (category==2){
if (income > 0 && income <= 18200) {
tax <- 0
} else if (income > 18200 && income <= 37000) {
tax <- (income - 18200) * .15
} else if (income > 37000 && income <= 80000) {
tax <- 3572 + (income - 37000) * .25
} else if (income > 80000 && income <= 180000) {
tax <- 17547 + (income - 80000) * .35
} else if (income > 180000 && Inf) {
tax <- 54547 + (income - 180000) * .45
}
return(tax)
}
}