So I have a csv file with three variables 'Team 1' 'Team 2' and 'Winner.' I want to create an adjacency matrix that has rownames=colnames. Is there any way to get this done? This is what I want:
A B C
A 0 2 1
B 1 0 3
C 2 4 0
So this particular matrix would indicate that A won from B 1 time and B from A 2 times and so on. The rownames indicate the winners.
For example, if my data looks like this:
Team A Team B Winner
Germany Argentina Germany
Croatia Germany Croatia
Argentina Croatia Argentina
would give the matrix
Germany Argentina Croatia
Germany 0 0 1
Argentina 1 0 0
Croatia 0 1 0
My code
data = as.matrix(read.csv("data.csv"))
labels = unique(c(data[,1],data[,2]))
A = matrix(0, length(labels),length(labels))
rownames(A) = colnames(A) <- labels
A
This creates the adjacency matrix, but how do I fill it in?