1

If I have a dataframe with duplicated rows we can find out with duplicated. See here:

a <- c(rep("A", 3))
b <- c("B", "B","C")
df <-data.frame(a,b, stringsAsFactors = F)
df
  a b
1 A B
2 A B
3 A C

duplicated(df)
FALSE TRUE FALSE

Here row 1 and 2 are identical. But what I need is a function that tells me that two (or more) columns contain the same elements, regardless of their order. Such a df could look like that:

df[2, ] <- df[2, 2:1]
df
  a b
1 A B
2 B A
3 A C

If we do not care about order rows 1 and 2 are still same, because both have A and B. So my expected output is for the latter df:

magicfunction(df)
FALSE TRUE FALSE
  • 1
    `duplicated(t(apply(df, 1, sort)))` Also check the linked section of the post there are lot of related posts with different ways. – Ronak Shah Jun 05 '19 at 08:07
  • 4
    @RonakShah Wow, my question about duplicates is a duplicate of a duplicate. This is ironic. Thank you for your help! –  Jun 05 '19 at 08:09

0 Answers0