I need to include or exclude the variable from a data set based on the factor variable.
If var 1 = 1 then include var2 and var3, otherwise exclude.
I tried:
Newdf<- ifelse((var1 == "1",c(var2),c(-var2)) ,
ifelse((var1 == "1",c(var3),c(-var3))
And with dplyr:
Newdf<- df %>%
select( if_else(var1== 1,var2,-var2))%>%
select( if_else(var1== 1,var3,-var3))
Thank you for your help.