Remove duplicated 2 columns permutations

前端 未结 2 1768
长发绾君心
长发绾君心 2020-12-19 11:22

I can\'t find a good title for this question so feel free to edit it please.

I have this data.frame

  section time to from
1       a    9  1    2
2           


        
2条回答
  •  离开以前
    2020-12-19 11:38

    mn <- pmin(s$to, s$from)
    mx <- pmax(s$to, s$from)
    int <- as.numeric(interaction(mn, mx))
    s[match(unique(int), int),]
      section time to from
    1       a    9  1    2
    3       a   12  2    3
    4       a   12  2    4
    6       a   12  3    4
    

    Credit for the idea goes to this question: Remove consecutive duplicates from dataframe and specifically @MatthewPlourde's answer.

提交回复
热议问题