First, I want to create and object containing my conditional statement. Then, I want to call this statement into ifelse. Thanks in advance for your help!
Example:
library(dplyr)
dd <- iris
# This code does the job but it gets messy when I have many statements
dd <- dd %>%
mutate(Box =
ifelse(Sepal.Length > 5 & Species == "setosa", "Box_1", NA))
# This code doesn't work but it's what I'd aim
st <- Sepal.Length > 5 & Species == "setosa"
dd <- dd %>%
mutate(Box =
ifelse(st, "Box_1", NA))
Aucun commentaire:
Enregistrer un commentaire