基于两列的子集重复
Subset duplicates based on two columns
我的数据是这样的:
A B
1 2
1A 2
1A 2
2 3
2 4
2 4
3A 0
3A 0
4A 1
4A 1
5 5
我想根据两列的值对数据进行子集化,并提取所有重复的记录。我尝试使用 cbind 和 unique,但它们仅提取唯一值。如果有帮助的话,我找不到反向子集函数。
谢谢
你可以试试
df1[duplicated(df1)|duplicated(df1, fromLast=TRUE),]
# A B
#2 1A 2
#3 1A 2
#5 2 4
#6 2 4
#7 3A 0
#8 3A 0
#9 4A 1
#10 4A 1
数据
df1 <- structure(list(A = c("1", "1A", "1A", "2", "2", "2", "3A",
"3A",
"4A", "4A", "5"), B = c(2L, 2L, 2L, 3L, 4L, 4L, 0L, 0L, 1L, 1L,
5L)), .Names = c("A", "B"), class = "data.frame", row.names = c(NA,
-11L))
我的数据是这样的:
A B
1 2
1A 2
1A 2
2 3
2 4
2 4
3A 0
3A 0
4A 1
4A 1
5 5
我想根据两列的值对数据进行子集化,并提取所有重复的记录。我尝试使用 cbind 和 unique,但它们仅提取唯一值。如果有帮助的话,我找不到反向子集函数。 谢谢
你可以试试
df1[duplicated(df1)|duplicated(df1, fromLast=TRUE),]
# A B
#2 1A 2
#3 1A 2
#5 2 4
#6 2 4
#7 3A 0
#8 3A 0
#9 4A 1
#10 4A 1
数据
df1 <- structure(list(A = c("1", "1A", "1A", "2", "2", "2", "3A",
"3A",
"4A", "4A", "5"), B = c(2L, 2L, 2L, 3L, 4L, 4L, 0L, 0L, 1L, 1L,
5L)), .Names = c("A", "B"), class = "data.frame", row.names = c(NA,
-11L))