Remove all unique rows

☆樱花仙子☆ 提交于 2019-11-28 12:31:47

Another option:

subset(df,duplicated(col1) | duplicated(col1, fromLast=TRUE))

Try:

> tdf <- table(df$col1)
a b c d 
3 1 1 3 

df[df$col1 %in% names(tdf)[tdf>1],]
> df
  col1 col2 col3
1    a    A    3
2    a    B    3
3    a    C    1
6    d    A    3
7    d    B    2
8    d    C    1

You can do this by creating an index with ave:

df[as.logical(ave(1:nrow(df), df$col1, FUN=function(x) length(x) > 1)), ]

produces

  col1 col2 col3
1    a    A    3
2    a    B    3
3    a    C    1
6    d    A    3
7    d    B    2
8    d    C    1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!