I have a melted matrix A:
A =
1 1 1
2 1 0
2 2 1
3 1 0
3 2 0
3 3 1
I want to convert it to a B matrix:
B:
1 0 0
0 1 0
0 0 1
This matrix is symmetric.
We can easily melt a matrix using 'reshape' package. How can we do that inversely?
It is easy to use a for loop but it is too slow.
B <- matrix(0,nrow=3,ncol=3)
for(i in 1:nrow(A))
{
B[A[i,1],A[i,2]] = A[i,3]
}