You should wrap your data into a list
{{6., 7.}, {6., 4.}, {1., 6.}, {4., 6.}, {7., 5.}, {6., 2.}, {6., 7.}, {6., 4.}}
and then apply the replacement rule outside the final bracket:
{{6., 7.}, {6., 4.}, {1., 6.}, {4., 6.}, {7., 5.}, {6., 2.}, {6., 7.}, {6., 4.}}/. {a_, b_} :> {a, b, If[a >= b, 1, 0]}
The repacement rule instructs Mathematica to replace any list of two elements of the form {a,b}
with the triplet {a,b,variable}
, where the variable
is 1 or 0 according to the values of a,b
. The underscores in {a_, b_}
mean that a
and b
are not meant to be literally the two symbols a
and b
, but they are patterns to which we assign the tags a
and b
for the purposes of the replacement.
The rule {a_, b_} :> {a, b, If[a >= b, 1, 0]}
fails if your matrix is 2 by 2, in which case you should use the more elaborate version {a_?NumericQ, b_} :> {a, b, If[a >= b, 1, 0]}
,which checks if a
is a number.
There are other ways of solving your problem, that may be more obscure but a lot faster for very large matrices.