-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior
Milestone
Description
I am not sure if I am doing something wrong, but If that is the case I cannot see what in next reproducible example:
data <- structure(list(x = c(1, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1,
-1, -1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1,
-1, -1), y = c(-1, -1, 1, 1, 2, 1, -1, 1, 1, 1, -1, 1, 1, 1,
1, -1, 1, -1, 1, 1, 2, -1, 1, -1, 1, 1, 1, 1, 1, 1)), row.names = c(NA,
-30L), class = c("tbl_df", "tbl", "data.frame"))
data %>%
mutate(dich = case_when(if_any(c(x, y), function(.x) {.x == 1}) ~ "green",
x==2 | y==2 ~ "blue",
TRUE ~ NA_character_)) %>%
pull(dich) %>% table(useNA = "ifany")
blue green
2 28
# but
data %>%
mutate(dich = case_when(if_any(c(x, y), function(.x) {.x == 1}) ~ "green",
if_any(c(x, y), function(.x) {.x == 2}) ~ "blue",
TRUE ~ NA_character_)) %>%
pull(dich) %>% table(useNA = "ifany")
green <NA>
28 2 Thank you!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior