I want substitute ifelse with if...else because I have exactly the same conditions with a lot of effects. I saw others question like Question14170778 but I can't apply the answear.
I know that if
statement is not vectorized unlike ifelse
df <- mtcars %>%
mutate(Tire = ifelse(mpg>18 & disp>160, "big",NA),
Bonus = ifelse(mpg>18 & disp>160, -100,NA),
Maintenance= ifelse(mpg>18 & disp>160, "expensive","cheap"))
and I try something like this but it dosn't work with 1 mutate so with 3....
df1 <- mtcars %>%
{ if(mtcars$mpg>18 & mtcars$disp>160) mutate(.,Tire = "big") else . }
Is there any other way to avoid writing 10 times the same lines ?