-2
比方說,我有一個這樣的測試數據:如何從data.tree對象獲取節點的深度?
library(data.tree)
df <- structure(list(parent = c("part1", "part3", "part7", "part4",
"part9", "part1"), child = c("part7", "part12", "part4", "part27",
"part10", "part13"), children = c("part4", "", "part27", "",
"", ""), children1 = c("part27", "", "", "", "", ""), pathString = c("Root/part1/part7/part4/part27",
"Root/part3/part12//", "Root/part7/part4/part27/", "Root/part4/part27//",
"Root/part9/part10//", "Root/part1/part13//")), .Names = c("parent",
"child", "children", "children1", "pathString"), row.names = c(NA,
6L), class = "data.frame")
df$children <- ""
df$children1 <- ""
我創建了一個data.tree如下:
test_tree <- as.Node(df)
print(test_tree, limit = 50)
我試圖讓每一父節點的深度樹從根。 嘗試閱讀文檔,但我找不到與樹的深度有關的任何內容。
R有沒有一種方法從這個data.tree圖中獲取樹的深度?