Remove all unique rows

后端 未结 3 2010
灰色年华
灰色年华 2020-12-11 04:33

I am trying to figure out how to remove all unique rows, from a data frame, but if it has a duplicate, I want that to stay in. For Example - I want all columns from this wi

3条回答
  •  既然无缘
    2020-12-11 05:23

    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
    

提交回复
热议问题