開始使用免費開始

鄰居

在網路分析中,探索頂點之間連結的型態常常很重要。方法之一是找出每個頂點的相鄰頂點。接著,你可以判斷即使彼此未直接相連的頂點,是否共享相同的鄰居,藉此看出兩個頂點是否透過其他節點存在間接關係。在本練習中,你會學到如何找出單一頂點的鄰居,以及成對頂點之間的共同鄰居。

本練習屬於課程

R 的 Network Analysis

檢視課程

練習說明

  • 使用 neighbors() 函式,找出以任意方式與頂點 12 相連的頂點、對頂點 12 指向一條邊的頂點,以及從頂點 12 接收一條有向邊的頂點。可透過在引數 mode 中選擇正確的值來達成。從 allinout 中擇一。
  • 判斷頂點 42 與 124 是否有共同鄰居。使用 neighbors() 建立向量 n1,其中包含從頂點 42 接收邊的那些頂點;再建立向量 n2,其中包含對頂點 124 指向邊的那些頂點。接著使用 intersection() 來找出同時出現在 n1n2 的頂點是否存在。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

library(igraph)

# Identify all neighbors of vertex 12 regardless of direction
___(g, '12', mode = c('___'))

# Identify other vertices that direct edges towards vertex 12
___(g, '12', mode = c('___'))

# Identify any vertices that receive an edge from vertex 42 and direct an edge to vertex 124
n1 <- ___(g, '___', mode = c('___'))
n2 <- ___(g, '___', mode = c('___'))
___(n1, n2)
編輯並執行程式碼