Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = tibble(X = c("a", "b", "c", "d"),
- Y = c("a1", "b1", "c1", "d1"),
- Z = c("a2", "b2", "c2", "d2"),
- all = list(c("a", "c"), c("b"), c("c", "c1"), c("d", "d2")))
- data %>%
- mutate(result = case_when(Y %in% all ~ Y,
- Z %in% all ~ Z,
- TRUE ~ "none"))
- # A tibble: 4 x 5
- X Y Z all result
- <chr> <chr> <chr> <list> <chr>
- 1 a a1 a2 <chr [2]> none
- 2 b b1 b2 <chr [1]> none
- 3 c c1 c2 <chr [2]> none
- 4 d d1 d2 <chr [2]> none
- # A tibble: 4 x 5
- X Y Z all result
- <chr> <chr> <chr> <list> <chr>
- 1 a a1 a2 <chr [2]> none
- 2 b b1 b2 <chr [1]> none
- 3 c c1 c2 <chr [2]> c1
- 4 d d1 d2 <chr [2]> d2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement