[英]Creating an igraph attribute overview
我想知道是否有可能從igraph元素中獲取一個數據框,其中包含所有頂點屬性作為colnames。 這看起來像是一件微不足道的事情,但到目前為止我無法讓它工作。 我所能做的就是
cbind(V(igraphE)$attr_1, V(igraphE)$attr_2, V(igraphE)$attr_3, V(igraphE)$attr_4)
當然,我可以通過訪問所有屬性名稱
list.vertex.attributes(igraphE)
必須有另一種方法來實現這一點 - 也許你們中的某個人知道如何去做。
編輯:示例
test_fun <- function(color1,color2,len){
vec <- replicate(len,sample(c(color1,color2,NA),1))
return(vec)
}
set.seed(50)
num_nodes<- 20
test_graph <- erdos.renyi.game(num_nodes, 1/6)
V(test_graph)$color_1 <- test_fun("darkgreen","blue",num_nodes)
V(test_graph)$color_2 <- test_fun("brown","blueviolet",num_nodes)
V(test_graph)$color_3 <- test_fun("red","green",num_nodes)
V(test_graph)$color_4 <- test_fun("red","green",num_nodes)
plot(test_graph, vertex.size=7)
預期結果:data.frame包括所有頂點屬性,屬性作為colnames
它可能涉及到誰 - 我自己就找到了答案。 它確實非常簡單而且非常直觀:
df <- as.data.frame(vertex.attributes(test_graph))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.