我相信你正在寻找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电子表格。 –