エッジ属性とサブセット化
この演習では、ネットワークのエッジに属性を追加し、それらを確認する方法を学びます。たとえば、友人同士の各ペアが週に何時間一緒に過ごすかを表す属性 '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>=___]]