Say I have the following data frame:
df <- data.frame(x=c("a","b","c"), y=c("p","q","p"))
df
x y
1 a p
2 b q
3 c p
How do I create a matrix out of column x reflecting co-membership to values in column y? In the data frame above, a and c share value p, so in the resulting adjacency matrix, I want their intersecting cell to have value 1, which stands for "co-affiliated" as opposed to 0 meaning "not co-affiliated".
The desired output looks like this:
a b c
a 0 0 1
b 0 0 0
c 1 0 0
*This and this questions are similar, but not exactly the same.