I have a vector in R, say c(2, 2, 3, 2, 3, 4, 4), and I want to build a square matrix of size n (the number of elements of the vector) that has a 1 if the element i of the vector has the same value of the element j , and 0 otherwise. In this example , the element [1,2] and [1,4] of the matrix must have a 1 because the first, second and fourth elements of the vector are the same. Is there a way to do this ? A command or function to build ? Something with combinations ? I would like to avoid loops like for.
Thank you !