Creating adjacency matrices and edge lists

We can represent social network data in different formats. We cover two common representations: sparse adjacency matrices and edge lists.

Taking data from the social networking site (from the previous recipe in this chapter—Downloading social network data using public APIs), this recipe shows how you can convert a data frame with membership information into a sparse adjacency matrix and then to an edge list.

In this application, nodes represent users of and an edge connects two nodes if they are members of at least one common group. The number of common groups for a pair of people will represent the weight of the connection.

Getting ready

If you have not yet installed the Matrix package, ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.