Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.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 边或顶点的动态属性上的子图_R_Igraph - Fatal编程技术网

R 边或顶点的动态属性上的子图

R 边或顶点的动态属性上的子图,r,igraph,R,Igraph,我有一个大图,我需要通过选择包含某个属性的边的顶点来过滤并创建一个子图。边有许多属性atti={att1,att2,…,attN} 我想根据选定的属性列表选择边 > require(igraph) > graph <- make_ring(9) #this is my original graph > V(graph)$name <- c("A", "B", "C", "D", "E", "F", "G", "H", "I") #name of vertices

我有一个大图,我需要通过选择包含某个属性的边的顶点来过滤并创建一个子图。边有许多属性atti={att1,att2,…,attN} 我想根据选定的属性列表选择边

> require(igraph)
> graph <- make_ring(9)  #this is my original graph
> V(graph)$name <- c("A", "B", "C", "D", "E", "F", "G", "H", "I")  #name of vertices
> E(graph)$att1 <- c(1,0,0,0,1,0,0,1,0)
> E(graph)$att2 <- c(0,3,1,0,0,1,0,0,1)
> E(graph)$att3 <- c(0,0,0,1,4,0,0,0,0)
> E(graph)$att4 <- c(1,0,1,0,2,1,0,0,0)

> # this is where I have issue. i don't know how to select vertices based on a dynamically selecting edges
> selected_atts <- c("att1", "att3")
> selected_vertices <- V(graph)[inc(E(graph)[which(selected_atts> 0)])] ## select all vertices that are linked by edges with att1 > 0 or att3 > 0 
> subgraph_list <- make_ego_graph(graph, order=1, selected_vertices) 

选定的属性是动态的。它们会发生变化,可能会有很多,因此我不想硬编码它们。

继续您的示例,您可以按名称引用边缘属性

edge_attr(graph)[["att1"]]
[1] 1 0 0 0 1 0 0 1 0
因此,在选定的边上循环并获取适当的边。然后制作子图

selected_atts <- c("att1", "att3")

KeepEdge = 1:ecount(graph)
for(SA in selected_atts) {
    KeepEdge = intersect(Keep, which(edge_attr(graph)[[SA]] > 0)) }

SG = subgraph.edges(graph, KeepEdge)
plot(SG)
selected_atts 0))}
SG=子图边(图,保留)
绘图(SG)

边属性函数非常有用!非常感谢。
selected_atts <- c("att1", "att3")

KeepEdge = 1:ecount(graph)
for(SA in selected_atts) {
    KeepEdge = intersect(Keep, which(edge_attr(graph)[[SA]] > 0)) }

SG = subgraph.edges(graph, KeepEdge)
plot(SG)