How can I delete certain rows according to two columns which have symmetricl values in data.table in R?

后端 未结 4 1478
粉色の甜心
粉色の甜心 2021-01-22 04:45

For example, I have a table as follows:

DT <- data.table(
  A = c(1,1,1,2,2,2,3,3,3), 
  B = c(1,2,3,1,2,3,1,2,3),
  key = \"A\"
)

I wand to

4条回答
  •  失恋的感觉
    2021-01-22 05:26

    if you only have two columns, then you could do:

     unique(do.call(function(A,B)data.table(A=pmin(A,B),B=pmax(A,B)),DT))
       A B
    1: 1 1
    2: 1 2
    3: 1 3
    4: 2 2
    5: 2 3
    6: 3 3
    

提交回复
热议问题