I have a dataframe of this structure:
A <- data.frame(A = c("B",NA,NA,NA),
B = c("C","D",NA,NA),
C = c(NA,NA,NA,NA),
D = c("A",NA,NA,NA))
Where A,B,C and D are units of my network. My problem is, is that I have a link A -> B, but not B -> A, which is just not documented in the data that I have. Also B -> D, but not D -> B for example. I want to manipulate this dataframe (or matrix rather) such that each link shows up in each column. The dataframe should then look like this:
B <- data.frame(A = c("B","D",NA,NA),
B = c("A","C","D",NA),
C = c("B",NA,NA,NA),
D = c("A","B",NA,NA))
In my original data, I have around 68.000 units (columns) and around 30 documented (one sided) links (rows). So my dataframe now is quite large, and I cannot check whether each link is actually documented twice (i.e. B exists in column A, but A does not exist in column B etc.). Keep in mind, it is actually possible that in some cases both links are already documented, I cannot be sure.
I hope I could present my problem clearly. I'd be glad for any useful ideas.
Thanks in advance
Here's one solution in base R: