Skip to content

Instantly share code, notes, and snippets.

@brshallo
Created November 29, 2018 22:13
Show Gist options
  • Save brshallo/44215074fd289d049aedbfd2bd2bf534 to your computer and use it in GitHub Desktop.
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)
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