I'm confused by what you mean by "match in column x." Is it that you want only values for which there is an x for each y? Like, you only want pairs for which there is both a #a
and a #b
(where #
represents the value in x)? (Adding a reprex with the data printed for ease of browsing).
library(dplyr, warn.conflicts = FALSE)
Dfab <- bind_rows(tibble(x = seq(1:5),
y = rep("a", 5)),
tibble(x = seq(1:7),
y = rep("b", 7)))
Dfab
#> # A tibble: 12 x 2
#> x y
#> <int> <chr>
#> 1 1 a
#> 2 2 a
#> 3 3 a
#> 4 4 a
#> 5 5 a
#> 6 1 b
#> 7 2 b
#> 8 3 b
#> 9 4 b
#> 10 5 b
#> 11 6 b
#> 12 7 b
Created on 2018-12-12 by the reprex package (v0.2.1.9000)
For example, in the case below, would you not want the row where x = 3 and y = a, since you don't have x = 3 and y = b?
Dfab2 <- tibble::tribble(
~x, ~y,
1L, "a",
2L, "a",
3L, "a",
4L, "a",
5L, "a",
1L, "b",
2L, "b",
4L, "b",
5L, "b",
6L, "b",
7L, "b"
)
Dfab2
#> # A tibble: 11 x 2
#> x y
#> <int> <chr>
#> 1 1 a
#> 2 2 a
#> 3 3 a
#> 4 4 a
#> 5 5 a
#> 6 1 b
#> 7 2 b
#> 8 4 b
#> 9 5 b
#> 10 6 b
#> 11 7 b
Created on 2018-12-12 by the reprex package (v0.2.1.9000)