Cumulative value of an edge or node attribute while descending an igraph object

点点圈 提交于 2019-12-02 06:51:23

You can indeed use data.tree for this. Though Aggregate will sum up from children towards parent, and from what I understand, you want to do the opposite. So the following will work:

library(data.tree)
df <- get.data.frame(g, what = "edges")
dtr <- FromDataFrameNetwork(df)
dtr$dtcum <- 0
dtr$Do(function(node) node$dtcum <- node$parent$dtcum + node$dt, filterFun = isNotRoot)
print(dtr, "dt", "dtcum")

This will print out as:

          levelName   dt dtcum
1 0                   NA  0.00
2  °--1             0.01  0.01
3      °--2         0.03  0.04
4          ¦--3     0.05  0.09
5          °--4     0.01  0.05
6              °--5 0.02  0.07
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!