这个问题在这里已经有了答案:
pair-wise duplicate removal from dataframe [duplicate]
(4 个回答)
4年前关闭。
我确定这很简单,但我有一个数据框
df <- data.frame(a = c(1, 2, 3),
b = c(2, 3, 1),
c = c(3, 1, 4))
而且我想要一个新的数据框,它包含行中值的唯一组合,而不管它们在哪一列中。所以在上面的情况下,我想要
a b c
1 2 3
3 1 4
我试过了
unique(df[c('a', 'b', 'c')])
但它认为 (1, 2, 3) 与 (2, 3, 1) 不同,这是我不想要的。
最佳答案
也许是这样的
indx <- !duplicated(t(apply(df, 1, sort))) # finds non - duplicates in sorted rows
df[indx, ] # selects only the non - duplicates according to that index
# a b c
# 1 1 2 3
# 3 3 1 4
关于r - 无论位置如何,寻找独特的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29819921/