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:
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:
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.
精彩评论