开发者

How to remove duplicate node's children (by tagging the node) in R?

Here is an reproducible data example

library(data.table)
testDT = fread(
"from   to
Root    A
A   x1
x1  y1
y1  z1
y1  B
Root    B
B   x3
x3  y2
Root    C")

An example visualization of the data:

How to remove duplicate node's children (by tagging the node) in R?

As you see, hierarchically, the same node B at level1 appears as a child of node y1. What I would like to do i开发者_如何学Gos remove if the repeating node B has children and tag it. The output I want is:

How to remove duplicate node's children (by tagging the node) in R?

The output table that i desired:

| from        | to            |
|-------------|---------------|
|     Root    |     A         |
|     A       |     x1        |
|     x1      |     y1        |
|     y1      |     z1        |
|     y1      |     B (-r)    |
|     Root    |     B         |
|     B       |     x3        |
|     x3      |     y2        |
|     Root    |     C         |

I had prepared a question to remove the node that caused the recursive build and they provided a solution thanks. However, this solution completely deletes node B connected to y1 against my will.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜