1

I have the following tidygraph tibble:

rstat_nodes <- data.frame(name = c("Hadley", "David", "Romain", "Julia"), sex = c("M","M","M","F"))
rstat_edges <- data.frame(from = c(1, 1, 1, 2, 3, 3, 4, 4, 4), 
                            to = c(2, 3, 4, 1, 1, 2, 1, 2, 3))
g <- tbl_graph(nodes = rstat_nodes, edges = rstat_edges)
g

It looks like this:

> g
# A tbl_graph: 4 nodes and 9 edges
#
# A directed simple graph with 1 component
#
# Node Data: 4 x 2 (active)
  name   sex  
  <fct>  <fct>
1 Hadley M    
2 David  M    
3 Romain M    
4 Julia  F    
#
# Edge Data: 9 x 2
   from    to
  <int> <int>
1     1     2
2     1     3
3     1     4
# … with 6 more rows

Is there a convenient way to split them into two pure tibbles one for node part another for edge part.

littleworth
  • 4,781
  • 6
  • 42
  • 76

1 Answers1

1

I am relatively new to tidygraphs.. Interesting to see what the data structure is like, but maybe this is what you are looking for?

# to get nodes
g %>% activate(nodes) %>% as_tibble()
# to get edges
g %>% activate(nodes) %>% as_tibble()
StupidWolf
  • 45,075
  • 17
  • 40
  • 72