My problem seems very simple, but I can’t solve it in the morning ...
I have a matrix like this:
[,1] [,2]
[1,] 1 2
[2,] 2 1
[3,] 2 1
[4,] 3 4
I want to select rows that have the same information, regardless of the order of the column. For example, line 1 (1; 2) and line2 (2; 1). Then I want to delete them, except for one.
I wrote this function, but it does not work ...
f<-function(x){
i<-1
repeat
{
a<-c()
a<-c(which(x[i,1]==x[,2] & x[i,2]==x[,1]))
if(!is.null(a)) {x<-x[-c(a),]}
if(i>=nrow(x)) {break} else {i<-i+1}
}
x
}
f(data)
Can anyone give me a hint of this?
source
share