I have a data frame of 205,000+ rows formatted as follows:
df <- data.frame(project.id = c('SP001', 'SP001', 'SP001', 'SP017', 'SP018', 'SP017'),
supplier.id = c('1224', '5542', '7741', '1224', '2020', '9122'))
In the actual data frame there are 6700+ unique values of project.id
. I would like to create an edge list that pairs suppliers who have worked on the same project.
Desired end result for project.id = SP001
:
to from
1224 5542
1224 7741
5542 7741
So far I've tried using split
to create a list by project.id and then running lapply+combn
to generate all possible combinations of supplier.id
within each list/group:
try.list <- split(df, df$project.id)
try.output <- lapply(try.list, function(x) combn(x$supplier.id, 2))
Is there a more elegant/efficient (read "computed in less than 2hrs") way to generate something like this?
Any help would be much appreciated
igraph
or similar packages - see for example here: #12136471 where I was doing the reverse. – Blank