Hi @StephanieBR, I hope you have already managed to find a solution for this yourself.
I am not sure if I quite understand what you're looking for, but maybe this, using gtools::combinations
?
# Data
df1 <- structure(list(A = c(1L, 3L, 5L, 2L), B = c(4L, 1L, 2L, 3L), C = c(3L, 5L, 4L, 3L), D = c(2L, 3L, 3L, 4L)), class = "data.frame", row.names = c(NA, -4L))
# Get ALL combinations using gtools::combinations
combs <- gtools::permutations(nrow(df1), 2)
# Loop through all the row combos and sum the numbers that match
# Note that we use `1` here instead of `2` as in the previous answer - you can compare them to see the difference
result <- apply(combs, 1, function(i) as.integer(df1[i[1], ] != df1[i[2], ]))
# Identify the results if needed
colnames(result) <- paste(combs[, 1], combs[, 2], sep = '_')
# Sum the mismatches
colSums(result)
#> 1_2 1_3 1_4 2_1 2_3 2_4 3_1 3_2 3_4 4_1 4_2 4_3
#> 4 4 3 4 3 4 4 3 4 3 4 4
# Or view the whole matrix of results. I have transposed the results here with `t()` because I think it is easier to view
t(result)
#> [,1] [,2] [,3] [,4]
#> 1_2 1 1 1 1
#> 1_3 1 1 1 1
#> 1_4 1 1 0 1
#> 2_1 1 1 1 1
#> 2_3 1 1 1 0
#> 2_4 1 1 1 1
#> 3_1 1 1 1 1
#> 3_2 1 1 1 0
#> 3_4 1 1 1 1
#> 4_1 1 1 0 1
#> 4_2 1 1 1 1
#> 4_3 1 1 1 1