【发布时间】:2017-04-15 16:52:02
【问题描述】:
我有一个有向图对象,其中两列节点(id、类型)和两列边(从、到)。有没有一种简单的方法来获取将 type 设置为顶点的图形?
顶点:
id type
1 a
2 a
3 b
4 c
边:
from to
1 2
2 4
3 4
1 3
转换为:
顶点:
id type
a a
b b
c c
边:
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)
【问题讨论】:
标签: r graph adjacency-matrix