Currently , I have 4 lines for a simple ifelse on 4 columns. I'm pretty new in R, how can I do this in a single line ? Thank you ! :)
I tried to do that in function like
my_function <- function(var) {
datamart_apprentissage <- mutate(datamart_apprentissage, var= ifelse(is.na(var), 0, 1))
}
my_function("VIE_OB3_1")
my_function("VIE_OB3_2")
my_function("VIE_OB3_3")
my_function("VIE_OB3_4")
but didnt work
datamart_apprentissage <- mutate(datamart_apprentissage, VIE_OB3_1 = ifelse(is.na(VIE_OB3_1), 0, 1))
datamart_apprentissage <- mutate(datamart_apprentissage, VIE_OB3_2 = ifelse(is.na(VIE_OB3_2), 0, 1))
datamart_apprentissage <- mutate(datamart_apprentissage, VIE_OB3_3 = ifelse(is.na(VIE_OB3_3), 0, 1))
datamart_apprentissage <- mutate(datamart_apprentissage, VIE_OB3_4 = ifelse(is.na(VIE_OB3_4), 0, 1))
Thank you !