如果叶子多次存在,请将其作为新节点添加到data.tree

时间:2019-07-19 11:32:56

标签: r tree

我有一棵树,我会撒谎为它添加更多的叶子。但是,如果一个叶子可以分配给多个节点,那么我希望它是一个单独的节点。

我尝试编写此函数:

输入1:data.frame

testDF <- data.frame(
  Reads = c("Read1", "Read1", "Read1", "Read2", "Read3", "Read4", "Read5"),
  Features = c(
    "Feature1", "Feature2", "Feature3",
    "Feature4", "Feature5", "Feature6",
    "Feature7"
   ),
  stringsAsFactors = F
)
testDF

  Reads Features
1 Read1 Feature1
2 Read1 Feature2
3 Read1 Feature3
4 Read2 Feature4
5 Read3 Feature5
6 Read4 Feature6
7 Read5 Feature7

输入2:data.tree

testTree <- as.Node(
   data.frame(
      pathString = c("Root/Feature1/F1", 
                     "Root/Feature1/F2", 
                     "Root/Feature3/F3")
   )
)
testTree

     levelName
1 Root        
2  ¦--Feature1
3  ¦   ¦--F1  
4  ¦   °--F2  
5  °--Feature3
6      °--F3

给出以下2个输入:

 Root        
  ¦--Read1
  ¦--Feature1
  ¦   ¦--F1  
  ¦   °--F2  
  ¦--Feature2
  ¦--Feature3
  ¦   °--F3
  ¦--Feature4
  ¦   °--Read2
  ¦--Feature5
  ¦   °--Read3
  ¦--Feature6
  ¦   °--Read4
  °--Feature7
      °--Read5

因此,由于Read1可以分配给多个要素(要素1,要素1和要素3),因此我想将其分配给上层节点。

0 个答案:

没有答案