1

I would like to remove cases where the combination of two columns also appears as a reverse combination in those two same columns

Below is the input and desired output.

SS of Tables

It doesn't matter if the first or second occurrence is kept.

Data:

df <- data.frame(
  "x1" = 1:6, 
  "x2" = c(2,1,4,3,6,5), 
  "x3" = c("a","b", "c","d","e","f"))
Frank
  • 66,179
  • 8
  • 96
  • 180
a.m.
  • 21
  • 1
  • 4
  • 2
    Can you please share your example input in a format I can copy/paste in to R? Images are a very unfriendly way to share data. `dput(your_input)` or `dput(head(you_input))` is an easy way to make a copy/pasteable R object. – Gregor Thomas Sep 04 '18 at 19:51
  • `nopes = unname(as.list(DT[, 2:1])); res = DT[!nopes, on=names(DT)[1:2]]`? Not sure if it works since there's no example to test with. – Frank Sep 04 '18 at 19:51
  • Sure, Try this: df <- data.frame("x1" = 1:6, "x2" = c(2,1,4,3,6,5), "x3" = c("a","b", "c","d","e","f")) – a.m. Sep 04 '18 at 20:30
  • with that data, you can do `subset(df,!duplicated(t(apply(df[-3],1,sort))))` – Onyambu Sep 04 '18 at 21:07
  • `df[!duplicated(t(apply(df[-3],1,sort))),]` – Onyambu Sep 04 '18 at 21:08
  • Excellent. That worked! Thanks Onyambu. – a.m. Sep 04 '18 at 21:16

1 Answers1

0

The first suggestion worked just fine for me:

subset(df,!duplicated(t(apply(df[-3],1,sort))))
Frank
  • 66,179
  • 8
  • 96
  • 180
a.m.
  • 21
  • 1
  • 4