For those of us not familiar with MRQAP it would help to provide an example of what you're trying to achieve.
If I understand correctly, you have a vector like this:
respondents <- sample(c(1, 2), size = 6, replace = TRUE)
respondents
#> [1] 2 1 2 1 1 1
And you want to make a matrix by comparing the vector to itself. You can do that with outer()
, telling it that the operation you are doing to compare these vectors is equality ==
outer(respondents, respondents, "==")
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] TRUE FALSE TRUE FALSE FALSE FALSE
#> [2,] FALSE TRUE FALSE TRUE TRUE TRUE
#> [3,] TRUE FALSE TRUE FALSE FALSE FALSE
#> [4,] FALSE TRUE FALSE TRUE TRUE TRUE
#> [5,] FALSE TRUE FALSE TRUE TRUE TRUE
#> [6,] FALSE TRUE FALSE TRUE TRUE TRUE
Or if you want it with 0
and 1
instead of TRUE/FALSE:
1L * outer(respondents, respondents, "==")
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 0 1 0 0 0
#> [2,] 0 1 0 1 1 1
#> [3,] 1 0 1 0 0 0
#> [4,] 0 1 0 1 1 1
#> [5,] 0 1 0 1 1 1
#> [6,] 0 1 0 1 1 1
Created on 2022-11-10 by the reprex package (v2.0.1)