0

I have a hierarchical data as below. But it has circular structure. I want to delete the rows that cause the circular structure.

orderNo from to group1
1 A B 0
2 B C 0
3 C A 0
4 A D 0
1 X Y 1
2 Y W 1
3 W X 1

Data is something like that. I want to remove 3th and 7th rows from dataset.

There is a problem similar to the one in the answer in the link.

How can i do this in R? Can anyone help me?

gokhan can
  • 189
  • 9
  • 1
    Pick any node, use DFS to find all nodes that are connected to it, and drop any edge that leads to an already visited node. Plenty documentation/algorithms out there to achieve something similar – Abhinav Mathur Feb 23 '22 at 13:49
  • 1
    there is a question here about finding cycles in igraph which might be helpful https://stackoverflow.com/questions/55091438/r-igraph-find-all-cycles if you convert your data to an igraph object you could use the solution there – gfgm Feb 23 '22 at 14:59

0 Answers0