Let’s say I have a data as below:
test_df_4 <- data.frame(inner_obj= c(1, 3, 2, 6, 5),
outer_obj = c(3, 4, 1, 7, 6))
I see there two separate objects, one consist of: 1, 2, 3, 4
and second one is: 5, 6, 7
. My understanding is that 2
goes into 1
, then 1
goes into 3
and finally 3
goes into 4
. For the second object it is: 5
goes into 6
and 6
goes into 7
. In my case these are code blocks nested in each other, so to compute 4
, I need to start from 2
, then 1
, then 3
, then 4
. For the second object: I need to start from 5
, then 6
, then 7
.
I would like to get a list with this order – for the first object it should be 2, 1, 3, 4
and for the second: 5, 6, 7
.
I know how I could find a starting points (roots):
root <- igraph::degree(igraph::graph_from_data_frame(test_df_4), mode = "in")
root <- as.integer(names(root)[which(root == 0)])
But I still have a problem what function should I use to get the desired order. I would prefer to use igraph
package.