filter column by count

Got it even shorter with count():

library(dplyr)

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"
) %>%
  semi_join(count(.,x) %>%
              filter(n > 1),
            by = "x"
  )

Dfab2
#> # A tibble: 8 x 2
#>       x y    
#>   <int> <chr>
#> 1     1 a    
#> 2     2 a    
#> 3     4 a    
#> 4     5 a    
#> 5     1 b    
#> 6     2 b    
#> 7     4 b    
#> 8     5 b
1 Like