I have data that looks similar to these two adjacency matrices:
data1999 <- data.frame(node1=c("A", "A", "B", "D", "B", "C", "D"),
node2=c("A", "A", "D", "B", "B", "C", "D"),
link=c(1, 1, 1, 1, 1, 1, 1),
stringsAsFactors = FALSE)
adj.m1999 <- reshape2::acast(data1999, node1 ~ node2)
> adj.m1999
A B C D
A 2 0 0 0
B 0 1 0 1
C 0 0 1 0
D 0 1 0 1
data2000 <- data.frame(node1=c("A", "A", "B", "C", "D", "C", "D"),
node2=c("A", "A", "B", "C", "D", "D", "C"),
link=c(1, 1, 1, 1, 1, 1, 1),
stringsAsFactors = FALSE)
adj.m2000 <- reshape2::acast(data2000, node1 ~ node2)
> adj.m2000
A B C D
A 2 0 0 0
B 0 1 0 0
C 0 0 1 1
D 0 0 1 1
Note that in 1999, node D and B have a link.
Note that in 2000, node D and C have a link.
Based on this information, I want to construct a new adjacency matrix (with all the nodes of my 2000 data) in which B-D and D-B have a value of 1 while the rest has a zero:
> result
A B C D
A 0 0 0 0
B 0 0 1 0
C 0 1 0 0
D 0 0 0 0
In my real-life data, data 1999 can have additional nodes that don't return in 2000 and vice versa.
Any ideas?