我相信你正在尋找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)
謝謝,這非常有用。該命令處理了我當前的數據,但我同意我應該先編譯Excel電子表格。 –