Created
November 29, 2018 22:13
-
-
Save brshallo/44215074fd289d049aedbfd2bd2bf534 to your computer and use it in GitHub Desktop.
Remove all rows that have a value in `col_b` that does not show-up in `col_a` (question sent)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse, quietly = TRUE) | |
(df <- tibble(col_a = c("a", "b", "c", "d", "d"), | |
col_b = c("b", "a", "d", "a", "e"))) | |
#> # A tibble: 5 x 2 | |
#> col_a col_b | |
#> <chr> <chr> | |
#> 1 a b | |
#> 2 b a | |
#> 3 c d | |
#> 4 d a | |
#> 5 d e | |
filter(df, col_b %in% col_a) | |
#> # A tibble: 4 x 2 | |
#> col_a col_b | |
#> <chr> <chr> | |
#> 1 a b | |
#> 2 b a | |
#> 3 c d | |
#> 4 d a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment