为这样的图形生成节点和边之后:
df <- structure(list(book1 = structure(1:4, .Label = c("refid1", "refid2",
"refid3", "refid7"), class = "factor"), book2 = structure(c(2L,
3L, 3L, 1L), .Label = c("", "refid1", "refid3"), class = "factor"),
book3 = structure(c(2L, 3L, 4L, 1L), .Label = c("", "refid1",
"refid2", "refid4"), class = "factor"), book4 = structure(c(2L,
3L, 4L, 1L), .Label = c("", "refid1", "refid3", "refid4"), class = "factor"),
book5 = structure(c(2L, 3L, 3L, 1L), .Label = c("", "refid2",
"refid6"), class = "factor"), book6 = structure(c(3L, 2L,
1L, 1L), .Label = c("", "refid1", "refid2"), class = "factor"),
book7 = structure(c(2L, 3L, 1L, 1L), .Label = c("", "refid1",
"refid5"), class = "factor")), .Names = c("book1", "book2",
"book3", "book4", "book5", "book6", "book7"), class = "data.frame", row.names = c(NA,
-4L))
library(dplyr)
library(igraph)
library(tidyr)
g<- df %>%
gather(key = "From", "To", na.rm = TRUE) %>%
graph_from_data_frame()
如何将节点和边缘保存到不同的csv文件中?