Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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_Graph_Adjacency Matrix - Fatal编程技术网

R-使用顶点属性igraph生成新的图形对象

R-使用顶点属性igraph生成新的图形对象,r,graph,adjacency-matrix,R,Graph,Adjacency Matrix,我有一个有向图对象,其中两列表示节点(id,type),两列表示边(from,to)。有没有一种简单的方法可以获得通过将type设置为顶点得到的图形 顶点: id type 1 a 2 a 3 b 4 c id type a a b b c c 边缘: from to 1 2 2 4 3 4 1 3 from to a a a c b c a b 转换为: 顶点: id type 1 a 2 a 3 b 4 c id

我有一个有向图对象,其中两列表示节点(id,type),两列表示边(from,to)。有没有一种简单的方法可以获得通过将type设置为顶点得到的图形

顶点:

id type
1  a
2  a
3  b
4  c
id type
a  a
b  b
c  c
边缘:

from to
1    2
2    4
3    4
1    3
from to
a    a
a    c
b    c
a    b
转换为:

顶点:

id type
1  a
2  a
3  b
4  c
id type
a  a
b  b
c  c
边缘:

from to
1    2
2    4
3    4
1    3
from to
a    a
a    c
b    c
a    b
我使用以下代码生成图形以获取上面的第一个图形对象:

nodes <- read.csv("1.toyNODES.CSV", header=T, as.is=T)
edges <- read.csv("1.toyEDGES.CSV", header=T, as.is=T)
graph <- graph_from_data_frame(d=edges, vertices=nodes, directed=T)

节点这将聚合组之间的边:

type.factor <- as.factor(V(your.g)$type)
type <- as.numeric(type.factor)
meta.g <- contract.vertices(your.g,type)
E(meta.g)$weight <- 1
meta.g <- simplify(meta.g)
type.factor