thomasp85 / tidygraph

A tidy API for graph manipulation
https://tidygraph.data-imaginist.com
Other
543 stars 61 forks source link

Bipartite Projection #150

Closed nabsiddiqui closed 2 years ago

nabsiddiqui commented 2 years ago

I am trying to switch from igraph to tidygraph, and I keep finding myself having to go back and forth due to bipartite projection. I was wondering if there is a way to do this with tidygraph or a desire to implement it? Even the current methods in igraph are very cumbersome.

For instance, I have an edge list of actors and films that they starred in. I also have a node list consisting of name and if it refers to an actor or film.

If two actors were in the same film, I would like to connect them together and have a new edge list with just the connections of the actors to run various measurements on them.

thomasp85 commented 2 years ago

I agree that there are situations were igraph is still needed - I designed tidygraph in such a way that it did not have to be a 100% stand in for igraph since the two packages work well together.

However I believe your problem can easily be solved with tidy graph (at least as I understand your task)

If you format your input edgelist as a data.frame with films as columns and actors as rows, and let each column be a logical vector with FALSE if the actor didn't occur in the film, and TRUE if they did, then tidygraph will read it in in the format you request.

However, if you prefer the igraph approach it is just as valid