邊的屬性與子設定
在這個練習中,你會學到如何為網路中的邊加入屬性並加以查看。舉例來說,我們會加入代表每對朋友每週相處時數的屬性「hours」。
本練習屬於課程
R 的 Network Analysis
練習說明
- 使用
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>=___]]