1

I have the following problem:

I have an k*2 matrix with unique rows (unique() command was applied before), so the essential part is, it has two columns.

Now I only want to keep the rows which are not a permutation of another row,

but in such a way that if there is a permutation, I do want to keep one of the two!

background: each element of this matrix is associated w/ a column of another data vector and I wantt to take differences of many 2 such vectors, and project on the resulting (difference) vector. But projecting on +/- the vector is the same, so this is for this application a duplicate.

Example:

     [,1] [,2]
[1,]    1    2
[2,]    3    4
[3,]    2    1

Desired result:

     [,1] [,2]
[1,]    1    2
[2,]    3    4

1 Answers1

1
  1. Create a copy of the matrix
  2. Sort each of its rows
  3. Find the indices of non-duplicate rows using the duplicated function
  4. Select these rows from the original matrix

or if the order does not matter, just run unique after step 2.

oseiskar
  • 3,282
  • 2
  • 22
  • 22