Removing duplicate combinations (irrespective of order)

Sort within the rows first, then use duplicated, see below:

# example data    
dat = matrix(scan('data.txt'), ncol = 3, byrow = TRUE)
# Read 90 items

dat[ !duplicated(apply(dat, 1, sort), MARGIN = 2), ]
#       [,1] [,2] [,3]
#  [1,]    1    2    3
#  [2,]    1    2    4
#  [3,]    1    2    5
#  [4,]    1    3    4
#  [5,]    1    3    5
#  [6,]    1    4    5
#  [7,]    2    3    4
#  [8,]    2    3    5
#  [9,]    2    4    5
# [10,]    3    4    5

Leave a Comment