How to order this two dependent columns in R [clos

2020-05-06 08:48发布

At my job we are trying to create paths among nodes. So, one of the results are in two columns (i, j) and we would like to create a path from that data, trying to do something like this, the column i have the control over the j, but then the second row controls the others, and so on. Thus, we can know te path of moving in these 5 nodes o points (x,y)

I have a data frame like this:

   i  j 
1  2  3
2  3  4
3  1  5
4  5  2
5  4  1

...and I need it like this, i ir order with j:

   i  j
1  1  5
2  5  2
3  2  3
4  3  4
5  4  1... and so on

The final solution should be something like this: 1->5->2->3->4->1

0条回答
登录 后发表回答