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