Select equivalent rows [A-B & B-A] [duplicate]

Like this:

unique(t(apply(mat, 1, sort)))

Note that output rows are sorted, so for example an “unmatched” row like c(5, 1) in the original data will appear as c(1, 5) in the output. If instead you want the output rows to be as they are in the input, then you can do:

mat[!duplicated(t(apply(mat, 1, sort))), ]

Leave a Comment