How to output duplicated rows

前端 未结 6 1726
情话喂你
情话喂你 2020-12-04 03:39

I have the following data:

x1  x2  x3  x4
34  14  45  53 
2   8   18  17
34  14  45  20
19  78  21  48 
2   8   18  5

In rows 1 and 3; and

6条回答
  •  囚心锁ツ
    2020-12-04 04:26

    Learned this one the other day. You won't need to re-order the output.

    s <- split(dat, do.call(paste, dat[-4]))
    Reduce(rbind, Filter(function(x) nrow(x) > 1, s))
    #   x1 x2 x3 x4
    # 2  2  8 18 17
    # 5  2  8 18  5
    # 1 34 14 45 53
    # 3 34 14 45 20
    

提交回复
热议问题