I need to do a simple data conversion in R for usage with igraph. My dataframe is in this format, grouped by GROUP
:
A GROUP
1 1 a
2 2 a
3 3 a
4 4 a
5 1 b
6 3 b
7 5 b
1. How do I expand the groups to get an undirected edgelist el
in this format?
A B
1 1 2
2 1 3
3 1 4
4 2 3
5 2 4
6 3 4
7 1 3
8 1 5
9 3 5
Note: no self-references 1-1, 2-2, 3-3, ...
2. How do I count A-B occurrences and create a weighted edgelist from el
?
A B weight
1 1 2 1
2 1 3 2
3 1 4 1
4 2 3 1
5 2 4 1
6 3 4 1
7 1 5 1
8 3 5 1