下面是与基础R一种可能性:
df1[df1$Cust %in% df1$Cust[duplicated(df1)],]
# Cust Weight
#1 1111 100
#2 1111 100
#3 1111 100
#7 1113 80
#8 1113 80
#9 1113 80
补充部分data.frame可以通过添加一个否定!
操作来获得:
df1[!df1$Cust %in% df1$Cust[duplicated(df1)],]
# Cust Weight
#4 1112 50
#5 1112 75
#6 1112 65
其产生在这个例子中相同的结果更一般的版本可以是在本实施例中使用
var.rows <- aggregate(Weight ~ Cust, df1, var)
df1[df1$Cust %in% var.rows$Cust[!var.rows$Weight],]
数据:
df1 <- structure(list(Cust = c(1111L, 1111L, 1111L, 1112L, 1112L, 1112L,
1113L, 1113L, 1113L), Weight = c(100L, 100L, 100L, 50L, 75L,
65L, 80L, 80L, 80L)), .Names = c("Cust", "Weight"),
class = "data.frame", row.names = c(NA, -9L))
如果你可以开始某种编码,这将是有益的。 –
此外,请提供所需的输出,因为它应该是什么混淆。 – lmo
欢迎来到SO。请编辑您的问题以包含所需的输出。另外,如果有更好的方法可以执行,您是否真的需要for循环? – C8H10N4O2