包文档?FromDataFrameNetwork
说明了如何指定方向
这可以是攀爬(从父母到孩子)或下降 (从孩子到父母)
Q1。为什么direction = "descen"
不起作用:
library(data.tree)
data(acme)
x = ToDataFrameNetwork(acme, direction = "climb")
head(x)
# from to
# 1 Acme Inc. Accounting
# 2 Acme Inc. Research
# 3 Acme Inc. IT
# 4 Accounting New Software
# 5 Accounting New Accounting Standards
# 6 Research New Product Line
x = ToDataFrameNetwork(acme, direction = "descen")
# Error in ToDataFrameNetwork(acme, direction = "descen") :
# direction descen unknown. Must be either climb or descen.
#of course i can manually make it from child to parent:
x_the_other_way = x[ , c('to', 'from')]
head(x_the_other_way)
# to from
# 1 Accounting Acme Inc.
# 2 Research Acme Inc.
# 3 IT Acme Inc.
# 4 New Software Accounting
# 5 New Accounting Standards Accounting
# 6 New Product Line Research
Q2。如何在将数据帧网络转换为树时指定方向?
xN <- FromDataFrameNetwork(x, direction = "climb")
# Error in FromDataFrameNetwork(x, direction = "climb") :
# unused argument (direction = "climb")
关于Q2的更新:算法将找出方向;用户不需要指定。我想它可能会根据“只有一个根”来判断它
xN = FromDataFrameNetwork(x)
xN_the_other_way = FromDataFrameNetwork(x_the_other_way)
xN
# levelName
# 1 Acme Inc.
# 2 ¦--Accounting
# 3 ¦ ¦--New Software
# 4 ¦ °--New Accounting Standards
# 5 ¦--Research
# 6 ¦ ¦--New Product Line
# 7 ¦ °--New Labs
# 8 °--IT
# 9 ¦--Outsource
# 10 ¦--Go agile
# 11 °--Switch to R
xN_the_other_way
# levelName
# 1 Acme Inc.
# 2 ¦--Accounting
# 3 ¦ ¦--New Software
# 4 ¦ °--New Accounting Standards
# 5 ¦--Research
# 6 ¦ ¦--New Product Line
# 7 ¦ °--New Labs
# 8 °--IT
# 9 ¦--Outsource
# 10 ¦--Go agile
# 11 °--Switch to R
谢谢 -
答案 0 :(得分:1)
ToDataFrameNetwork
的帮助说:
?ToDataFrameNetwork
direction when converting to a network, should the edges point from root to children ("climb") or from child to parent ("descend")?
因此,您必须指定climb
或descend
。
(错误消息中有拼写错误,已在github中修复,尚未在CRAN上修复)。
关于第二个问题:是的,前两列中提供的网络必须是树,即它只能包含一个根。因此,算法很容易找出网络的指定方向。