Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R中的igraph包传播顶点属性_R_Igraph - Fatal编程技术网

使用R中的igraph包传播顶点属性

使用R中的igraph包传播顶点属性,r,igraph,R,Igraph,我正在寻找一种智能的方法,使用带有R语言的IGRAPHE包在有向图中传播顶点属性。我对网络的命名法和性质不太熟悉,但我会尽力的 例如: library(igraph) library(dplyr) from_to_df = data.frame(from = c("a", "b", "c", "d", "e", "f"), to = c("c", "c", "d", "e", "g", "g") ) attribut

我正在寻找一种智能的方法,使用带有R语言的IGRAPHE包在有向图中传播顶点属性。我对网络的命名法和性质不太熟悉,但我会尽力的

例如:

library(igraph)
library(dplyr)
from_to_df = data.frame(from = c("a", "b", "c", "d", "e", "f"),
                    to = c("c", "c", "d", "e", "g", "g")
                    )
attributes_i_have = c(NA, NA, NA, 2, NA, NA, 1)
attributes_i_want_to_have = c(2, 2, 2, 2, 1, 1, 1)
color = c('red', 'red', 'red', 'green', 'red', 'red', 'green')

network_i_have = graph_from_data_frame(from_to_df, directed=T) %>%
  set_vertex_attr("label", value = attributes_i_have) %>%
  set_vertex_attr("color", value = color) 

plot(network_i_have)
正如名字所说,这是一个图,我想对顶点属性进行反向传播,得到这样一个图:

network_i_want_to_have = graph_from_data_frame(from_to_df, directed=T)%>%
  set_vertex_attr("label", value = attributes_i_want_to_have) %>%
  set_vertex_attr("color", value = color) 

plot(network_i_want_to_have)
感谢您的帮助