This is specific to the 3x3 case
test_rel <- function(x) {
holder <- matrix(, nrow = 3, ncol = 3)
holder[1,] = x[,2] >= x[,1]
holder[2,] = x[,3] >= x[,1]
holder[3,] = x[,3] >= x[,2]
return(holder)
}
mat <- matrix(1:9, nrow=3, byrow = TRUE)
mat
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 4 5 6
#> [3,] 7 8 9
test_rel(mat)
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
# more interesting case
mat <- matrix(sample(1:9,9), nrow = 3, ncol = 3)
mat
#> [,1] [,2] [,3]
#> [1,] 3 5 8
#> [2,] 7 9 6
#> [3,] 2 4 1
test_rel(mat)
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE FALSE FALSE
#> [3,] TRUE FALSE FALSE
To generalize to the NxN case, a bit of metaprogramming can take N and generate a function appropriately expanded.