R dplyr - distinct accross all columns

Viewed 5958

Is there a way to specify dplyr::distinct should use all column names without resorting to nonstandard evaluation?

df <- data.frame(a=c(1,1,2),b=c(1,1,3))

df %>% distinct(a,b,.keep_all=FALSE)          # behavior I'd like to replicate

vs

df %>% distinct(everything(),.keep_all=FALSE) # with syntax of this form
2 Answers

As of version 1.0.5 of dplyr, the two following options yield the same output.

df <- data.frame(a = c(1, 1, 2),
                 b = c(1, 1, 3))

df %>% distinct(a, b)

  a b
1 1 1
2 2 3

df %>% distinct(across(everything()))

  a b
1 1 1
2 2 3

No reason to specify .keep_all = FALSE argument as this is the default.

You could also use tibble() instead of data.frame()

Related