is there a better way to have multiple condition in order to simplify my code. here is an example of what I'm talking about.
library(data.table)
test <- data.table(dx1 <- c("a", "b", "c"),
dx2 <- c("b", "c", "d"),
dx3 <- c("a", "f", "g"))
condition <- c("a", "b")
# This is what I want to simplify
test[,dx4 := ifelse(dx1 %in% condition|
dx2 %in% condition |
dx3 %in% condition, 1, 0)]
Thank you
Aucun commentaire:
Enregistrer un commentaire