Skip to content

Conduct pairwise column comparisons without comparing a column to itself

1 message · jim holtman

#
A little different solution, but it gives you the matches and the
columns in a more compact form.  You can always take the data and use
it to put into your array.
[,1] [,2] [,3]
[1,]    1    1    2
[2,]    2    3    3
+     match <- which(same[, cbn[1, .col]] & same[, cbn[2, .col]])
+     if (length(match) == 0) return(NULL)  # no matches
+     # now return the values
+     cbind(LA=X[match, 2 * cbn[1, .col]],
+           LB=X[match, 2 * cbn[2, .col]],
+           col1=cbn[1, .col],
+           col2=cbn[2, .col])
+ })
c1 c2 c3 c4 c5 c6
 [1,]  1  2  1  2  1  3
 [2,]  4  4  3  3  2  2
 [3,]  3  3  2  2  1  4
 [4,]  2  4  4  3  1  3
 [5,]  4  4  4  1  2  1
 [6,]  1  3  3  3  2  1
 [7,]  3  4  4  2  2  2
 [8,]  2  1  4  4  3  3
 [9,]  4  3  2  4  2  3
[10,]  3  2  2  3  1  4
LA LB col1 col2
[1,]  4  3    1    2
[2,]  3  2    1    2
[3,]  4  2    1    3
[4,]  3  2    2    3
[5,]  4  3    2    3

        
On 10/19/07, Luke Neraas <lukasneraas.r at gmail.com> wrote: