2016-11-11 37 views
0

親愛的#1的社區,我目前使用R鍵編譯歸屬網絡中節點企業/傘狀組織和關係被定義爲「會員」R /網絡分析 - 如何通過節點的屬性創建邊緣

。此刻,我的名單仍然很小,我可以根據節點的位置創建邊緣如下,(我用的igraph):但是

g <- igraph::add_edges(g, c(1,51, 
          1,52, 
          1,53, 
          1,54)) 

,我添加新節點和最終的網絡將包括至少有500個組織。這意味着每次添加新節點時,節點的位置都可以更改。由於每次添加新節點都無法重新生成邊緣,是否有一種方法可以添加知道節點名稱的邊緣?

節點的名稱被視爲一個屬性,我試圖用同樣的命令,上面包括姓名 - 而不是位置 - 但它沒有工作:

g <- igraph::add_edges(g, c(V(g)$name=="Company1", V(g)$name == "Umbrella2")) 

如何我任何建議可以通過指定名稱而不是位置創建邊?

回答

0

我相信你正在尋找as.numeric(V(g)["Company1"])

我強烈建議針對建立您的網絡結構一個R腳本,但。即使對於一個小型網絡,我也會將我的數據輸入到excel文件中,創建一個R-script,將數據作爲邊界列表讀取並從中創建一個igraph。這樣,您可以隨時添加您的公司和組織,更好地監控數據實際進入您的網絡的情況,我想這就是您首先要查找的內容。儘管如此,這個問題將會超出這個問題。

至於添加節點的名稱,我寫這個例子給你,我希望是教學法。

library(igraph) 

# Make an empty Bipartite graph 
g <- make_bipartite_graph(0, NULL, directed=TRUE) 
g <- delete_vertices(g, 1) 


# Create vertices of two different types: companies and umbrellas 
g <- add_vertices(g, 5, color = "red", type=TRUE, name=paste("Company", 1:5, sep="_")) 
g <- add_vertices(g, 2, color = "blue", type=FALSE, name=paste("Umbrella", 1:2, sep="_")) 

# In a bipartate graph edges may only appear BETWEEN verticies of different types. Companies 
# can belong to umbrellas, but not to each other. 

# Look at the types: 
ifelse(V(g)$type, 'Company', 'Umbrella') # true for companies, false for umbrellas 

# Lets add some edges one by one. This is what I believe you're asking for in the question: 
g <- add_edges(g, c(as.numeric(V(g)["Company_1"]), as.numeric(V(g)["Umbrella_1"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_1"]), as.numeric(V(g)["Umbrella_2"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_2"]), as.numeric(V(g)["Umbrella_1"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_3"]), as.numeric(V(g)["Umbrella_1"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_4"]), as.numeric(V(g)["Umbrella_2"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_5"]), as.numeric(V(g)["Umbrella_2"]))) 

# Note that "Company_1" belongs to two umbrella organisations, as I assume your companies can: 
plot(g) 
+0

謝謝,這非常有用。該命令處理了我當前的數據,但我同意我應該先編譯Excel電子表格。 –

相關問題