【发布时间】:2017-05-13 18:31:44
【问题描述】:
我想使用 R 中的 data.tree 库将边缘列表转换为树对象。
这是我的代码:
library(data.tree)
edges <- read.csv("data.csv")
colnames(edges) <- c("source", "target")
R1 <- data.frame(Parent=edges$source, Child=edges$target)
R2<- data.frame(Parent=c("earth","earth","forest","forest","ocean","ocean","ocean","ocean"),
Child=c("ocean","forest","tree","sasquatch","fish","seaweed","mantis shrimp","sea monster"))
现在,如果我运行 tree <- FromDataFrameNetwork(R2),一切正常。但是如果我这样做tree <- FromDataFrameNetwork(R1),我会收到以下错误:
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?
这怎么可能?
R1 如下所示:
Parent Child
1 1 6
2 4 2
3 3 5
4 1 4
5 1 5
6 5 3
R2 看起来像这样:
Parent Child
1 earth ocean
2 earth forest
3 forest tree
4 forest sasquatch
5 ocean fish
6 ocean seaweed
7 ocean mantis shrimp
8 ocean sea monster
【问题讨论】:
-
在 R1 中,3 是 5 的父节点,5 是 3 的父节点。这怎么可能在树中?