开始使用免费开始使用

创建 igraph 对象

在这里,您将学习如何从边列表中存储的数据创建一个 igraph "对象"。这些数据表示一组学生之间的友谊关系。您还将学习如何对该网络进行基础可视化。

friends 数据框中的每一行都表示网络中的一条边。

本练习是课程的一部分

R 中的网络分析

查看课程

练习说明

  • 使用 head() 函数查看数据框 friends 的前几行。
  • 使用 as.matrix() 将数据框 friends 转换为新的对象 friends.mat
  • 使用 graph.edgelist() 将该变量转换为 igraph 对象 g
  • 使用 plot() 对该网络进行基础绘图。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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)

编辑并运行代码