好的,我有两列data.frame,其变量号为-d
到child
。 (另两列为参考)
head
我只希望三行用于唯一的dat <- read.table(header=TRUE, stringsAsFactors=FALSE, text="
head child UID logic
1 01001 01001 1 FALSE
2 01001 01021 2 TRUE
3 01001 01047 3 TRUE
4 01001 01051 4 TRUE
5 01001 01085 5 TRUE
6 01001 01101 6 TRUE
7 01003 01003 7 FALSE
8 01003 01025 8 TRUE
9 01003 01053 9 TRUE
10 01003 01097 10 TRUE
11 01003 01099 11 TRUE
12 01003 01129 12 TRUE
13 01003 12033 13 TRUE
14 01005 01005 14 FALSE
15 01005 01011 15 TRUE
16 01005 01045 16 TRUE
17 01005 01067 17 TRUE
18 01005 01109 18 TRUE
19 01005 01113 19 TRUE
20 01005 13061 20 TRUE
21 01005 13239 21 TRUE
22 01005 13259 22 TRUE")
和一列head
。
如果您有更好的建议,我愿意接受。
我添加了其他列child
和UID
供参考,但可以将其删除。
在尝试中,我尝试转换为带有边列表的图形,然后转换为JSON。
logic
所需的输出:
# make graph ##########
library(tidyverse)
library(igraph)
library(jsonlite)
gdat <- select(dat, head, child)
mdat <- as.matrix(gdat)
edge_dat <- graph_from_edgelist(mdat)
plot.igraph(edge_dat)
jdat <- toJSON(mdat, matrix = "rowmajor")
答案 0 :(得分:1)
是您想要的吗?
{{1}}