将嵌套操作转换为用例

时间:2016-03-31 18:48:01

标签: r dplyr igraph

输入: input1:operations.csv

| id   | operation   | sub_start_id   | sub_return_id   | eq_parent_id   |
| ---- | ----------- | -------------- | --------------- | -------------- |
| 1    | x           | NA             | NA              | NA             |
| 2    | x1          | 4              | NA              | 1              |
| 3    | x2          | NA             | NA              | 1              |
| 4    | k           | NA             | NA              | NA             |
| 5    | k1          | NA             | NA              | 4              |
| 6    | k2          | NA             | NA              | 4              |
| 7    | L           | NA             | 2               | NA             |
| 8    | L1          | NA             | NA              | 7              |
| 9    | L2          | NA             | NA              | 7              |
| 10   | L3          | NA             | NA              | 7              |

input2:operation_relations.csv

| from   | to   |
| ------ | ---- |
| NA     | 1    |
| 2      | 3    |
| 4      | 7    |
| 5      | 6    |
| 8      | 9    |
| 8      | 10   |

这里是2输入数据框的代码:

nodes <- data.frame("id" = 1:10, 
                    "operation" = c('X', 'X1', 'X2', 'K', 'K1', 'K2', 'L', 'L1', 'L2', 'L3'),
                    "sub_start_id" = c(NA, 4, rep(NA, 8)),
                    "sub_return_id" = c(rep(NA, 6), 2, rep(NA, 3)),
                    "eq_parent_id" = c(NA, 1, 1, NA, 4, 4, NA, 7, 7, 7))

links = data.frame("from" = c(NA, 2, 4, 5, 8, 8),
                   "to"   = c(1, 3, 7, 6, 9, 10))

我需要输出如下:

预期产出:

顶级用例

1. x

用例x

1. x1
2. x2

用例x1

1. k
2. L

用例k

1. k1
2. k2

用例L

1. L1
2. L2
3. L3

如何在R中执行此操作,有没有办法用igraph表示它? 请查看下面的图像链接,以便更好地查看问题。

nested operations photo

0 个答案:

没有答案