You should consider to use or learn dplyr.
You can see dplyr with this link
Also return statement should be changed.
I think this code isn't looks elegant, but still you can use.
library(dplyr)
# example data
credit_data = data.frame(
O = c(0,0,1,1),
I = c(0,1,0,1)
)
# I changed variables as C, O, I it's too long.
Purchase = function(C){
sapply(1:nrow(C), function(i){
if(!C$O[i] && !C$I[i] ) return ("none")
if(C$O[i] && C$I[i] ) return ("one_off")
if(!C$O[i] && C$I[i]) return ("installment")
if(C$O[i] && C$I[i]) return ("both_oneoff_installment")
})
}
credit_data %>%
mutate(Purchase_Type = Purchase(credit_data))
Regards.