更新时间:2023-12-01 11:35:34
duplicated()
有一个 data.frame
的方法,就是专门为这种类型设计的任务:
duplicated()
has a method for data.frame
s, which is designed for just this sort of task:
df <- data.frame(a = c(1:4, 1:4),
b = c(4:1, 4:1),
d = LETTERS[1:8])
df[!duplicated(df[c("a", "b")]),]
# a b d
# 1 1 4 A
# 2 2 3 B
# 3 3 2 C
# 4 4 1 D