I have an igraph
object g
made from dataframe df
:
df <- data.frame(c(0,1,2,2,4), c(1,2,3,4,5), c(0.01, 0.03, 0.05, 0.01, 0.02))
colnames(df) <- c('parent_id', 'id', 'dt')
g <- graph_from_data_frame(df)
Edges are made between parent_id
and id
.
> g
IGRAPH DN-- 6 5 --
+ attr: name (v/c), dt (e/n)
+ edges (vertex names):
[1] 0->1 1->2 2->3 2->4 4->5
Change in thickness dt
is the edge attribute. This can be thought of as the change in thickness between a 'parent' and 'child' iceberg (this is my problem/project).
list.edge.attributes(g)
[1] "dt"
to visualize:
plot(g, edge.label=E(g)$dt)
Example of nodes and edge attribute 'dt'
I need to find the cumulative sum of dt
at each node while descending from parent to child.
When thinking in terms of 'ancestor', 'parent' and 'child' nodes, this is equivalent to getting the cumulative sum of dt
for all ancestors at each 'child' node.
Cumulative dt
assigned as edge attribute, anticipated outcome example
It is OK if these cumulative values are assigned as new node or edge attributes, or another form of output.
I have tried 1) the network.aggregate
function in the RNewsflow
package & 2) the aggregate
function in the data.tree
package.
Thank you in advance for interest and help.
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:This will print out as: