O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a bipartite network graph

Let's say we have a set of groups and a set of users with each user belonging to several groups and each group potentially has several members.

We can represent this information as a bipartite graph with the groups forming one set, the users forming the other, and edges linking members of one set to the other. You can use the graph.incidence function from the igraph package to create and visualize this network:

> set.seed(2015) > g1 <- rbinom(10,1,.5) > g2 <- rbinom(10,1,.5) > g3 <- rbinom(10,1,.5) > g4 <- rbinom(10,1,.5) > membership <- data.frame(g1, g2, g3, g4) > names(membership) [1] "g1" "g2" "g3" "g4" > rownames(membership) = c("u1", "u2", "u3", "u4", "u5", "u6", "u7", "u8", "u9", "u10") > rownames(membership) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required