這裏的另一種可能的基礎R解決方案
indx <- with(df, ave(A, A, FUN = length))
df[indx > 1, ]
# A B C
# 1 14 apple 45
# 2 14 bannaa 23
# 4 16 door 12
# 5 16 ear 325
或者使用data.table
包
library(data.table)
setDT(df)[, .SD[.N > 1], by = A]
# A B C
# 1: 14 apple 45
# 2: 14 bannaa 23
# 3: 16 door 12
# 4: 16 ear 325
或
setDT(df)[, if(.N > 1) .SD, by = A]
最後,使用rle
## df <- df[order(df$A), ] # If the data isn't sorted by `A`, you''ll need to sort it first
indx <- rle(df$A)$lengths
df[rep(indx > 1, indx), ]
# A B C
# 1 14 apple 45
# 2 14 bannaa 23
# 4 16 door 12
# 5 16 ear 325
嗯,'.SD [.N>。]'似乎很常見,不是嗎?然後優化時間。 – Arun 2014-11-03 23:19:30
@阿倫,我在(也見[這裏](http://stackoverflow.com/questions/26703764/find-duplicated-rows-with-original/26704121?s=1|0.0000#26704121))送我一封電子郵件與指示:) – 2014-11-04 09:14:48