首先,我想创建包含条件语句的对象。然后,我想把这句话称为ifelse。在此先感谢您的帮助!
示例:
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))