Skip to content

Instantly share code, notes, and snippets.

@fmichonneau
Last active December 8, 2016 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmichonneau/511913355ac56db148e2f924f97df0c3 to your computer and use it in GitHub Desktop.
Save fmichonneau/511913355ac56db148e2f924f97df0c3 to your computer and use it in GitHub Desktop.
# Resolving this: http://stackoverflow.com/questions/32035865/r-remove-rows-from-a-data-frame-that-contain-a-duplicate-of-either-combination-o
# using dplyr
Var1 <- c(1,2,3,4,5,5)
Var2 <- c(4,3,2,1,5,5)
f <- c("blue","green","yellow","red","orange2","grey")
g <- c("blue","green","yellow","red","orange1","grey")
testdata <- data.frame(Var1,Var2,f,g)
library(dplyr)
testdata %>%
rowwise() %>%
mutate(key = paste(sort(c(Var1, Var2)), collapse="")) %>%
distinct(key, .keep_all=T) %>%
select(-key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment