I would like to know if there is a function that applies an identifier to all nodes in a given dendrogram (binary tree).
So I want a function that after it on a given tree would do the following:
attr(tr,"ID") ## should give 1 or 1
attr(tr[[1]],"ID") ## should give 2 or 10
attr(tr[[2]],"ID") ## should give 3 or 11
attr(tr[[c(1,1)]],"ID") ## should give 4 or 100
etc...
And, if given to start with binaryID 110 (ID of Head Node)
it's 1st child ID should be 1100 it's 2nd child ID should be 1101
Note:
- dendrapply()
applies a function to all nodes in a tree
Package using= "stats"
D=rbind(
+ c(1,1,1,1,1),
+ c(1,2,1,1,1),
+ c(2,2,2,2,2),
+ c(2,2,2,2,1),
+ c(3,3,3,3,3),
+ c(3,3,3,3,2))
Ddend=as.dendrogram(hclust.vector(D))
funID<-function(tr,StartID){
.....
attr(n,"ID")= ID # for all the nodes in tr
}
What would funID be?