How do you retain all distinct rows in a data frame excluding certain columns by specifying only the columns you want to exclude. In the example below
library(dplyr)
dat <- data_frame(
x = c("a", "a", "b"),
y = c("c", "c", "d"),
z = c("e", "f", "f")
)
I'd like to return a data frame with all distinct rows among variables x
and y
by only specifying that I'd like to exclude column z
. The data frame returned should look like the data frame returned from here
dat %>% distinct(x, y)
You would think you can do the following, but it results in an error
dat %>% distinct(-z)
I prefer a tidyverse solution