I have a table (Table 1) that has matched pairs as rows, like this:
ID | Neighbour |
---|---|
Cell_A | Cell_B |
Cell_A | Cell_C |
Cell_D | Cell_C |
Cell_D | Cell_E |
and what I want is a table like this:
ID | Neighbour | Neighbour |
---|---|---|
Cell_A | Cell_B | Cell_C |
Cell_D | Cell_C | Cell_E |
I have tried using dcast with ID ~ neigbour but end up with an ID column, and then every Cell_* listed as their own column, and NA where there's no match (ie. Cell_A/Cell_D = NA).
I also tried pivot_wider(data = table1, id_cols = ID, values_from = neighbour)
and got an error (Error 1: column 1 must be named).
What's the obvious step that I'm missing here? Thanks in advance!!