开发者

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

开发者 https://www.devze.com 2022-12-07 17:53 出处:网络
Here is an reproducible data example library(data.table) testDT = fread( "fromto RootA Ax1 x1y1 y1z1 y1B

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

精彩评论

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

关注公众号