Remove duplicated 2 columns permutations

前端 未结 2 1769
长发绾君心
长发绾君心 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.

    0 讨论(0)
  • 2020-12-19 11:45

    You can try using sort within the apply function to order the combinations.

    mydf[!duplicated(t(apply(mydf[3:4], 1, sort))), ]
    #   section time to from
    # 1       a    9  1    2
    # 3       a   12  2    3
    # 4       a   12  2    4
    # 6       a   12  3    4
    
    0 讨论(0)
提交回复
热议问题