0
votes

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

  • I need of a function that invert tidyverse functions.
1
I don't think there is any general way to "invert" tidyverse functions, at least not without defining what "invert" would mean more generally. In this example though, your desired output can be achieved with df[duplicated(df$x.1),] , and the distinct values are given by df[!duplicated(df$x.1),] - IceCreamToucan

1 Answers

3
votes

You can try:

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

      n
  <int>
1    10