neves
neves

Reputation: 796

Invert `tidyverse` functions

I have the follow df:

set.seed(126)

df <- data.frame(
  x = replicate(2, sample(1:25, 25, replace = TRUE))
)

For return distinct values:

library(tidyverse)
library(magrittr)

df %>% distinct(x.1) %>% count()

# A tibble: 1 x 1
      n
  <int>
1    17

But, I want return duplicated values, instead distincts. I try:

df %>% !distinct(x.1) %>% count()

Error in distinct(x.1) : object 'x.1' not found

df %>% negate(distinct(x.1)) %>% count()

Error: Can't convert a data.frame object to function

df_1 %>% not(distinct(x.1)) %>% count()

Error in distinct(x.1) : object 'x.1' not found

Upvotes: 0

Views: 170

Answers (1)

tmfmnk
tmfmnk

Reputation: 40171

You can try:

df %>%
 filter(duplicated(x.1)) %>%
 count()

      n
  <int>
1    10

Upvotes: 3

Related Questions