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