边属性与子集筛选
在本练习中,您将学习如何为网络中的边添加属性并查看它们。例如,我们会添加名为 "hours" 的属性,用来表示每对朋友每周在一起相处的小时数。
本练习是课程的一部分
R 中的网络分析
练习说明
- 使用
set_edge_attr(),从向量hours创建名为 "hours" 的新边属性。 - 使用
edge_attr()查看所有边属性。 - 查看所有包含人物 "Britt" 的边。
- 查看属性
hours大于或等于 4 小时的所有边。
交互式实操练习
通过完成这段示例代码来试试这个练习。
library(igraph)
# View hours
hours
# Create new edge attribute called 'hours'
g <- set_edge_attr(g, ___, value = ___)
# View edge attributes of graph object
___(g)
# Find all edges that include "Britt"
E(g)[[.inc('___')]]
# Find all pairs that spend 4 or more hours together per week
E(g)[[hours>=___]]