LoslegenKostenlos loslegen

Creating an igraph object

Here you will learn how to create an igraph 'object' from data stored in an edgelist. The data are friendships in a group of students. You will also learn how to make a basic visualization of the network.

Each row of the friends dataframe represents an edge in the network.

Diese Übung ist Teil des Kurses

Network Analysis in R

Kurs anzeigen

Anleitung zur Übung

  • Inspect the first few rows of the dataframe friends using the function head().
  • Create new object friends.mat from the dataframe friends using as.matrix().
  • Convert variable to an igraph object g using graph.edgelist().
  • Make a basic plot of the network using plot().

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Load igraph
library(igraph)

# Inspect the first few rows of the dataframe 'friends'
___(friends)

# Convert friends dataframe to a matrix
friends.mat <- ___(friends)

# Convert friends matrix to an igraph object
g <- graph.edgelist(___, directed = FALSE)


# Make a very basic plot of the network
___(g)

Code bearbeiten und ausführen