tree_sum: Aggregate values in tips to internal nodes

Description Usage Arguments Examples

View source: R/prep_data.R

Description

Given a value associated with each tip in a tree, this calculates, for each internal node, the sum across all tips that descend from it.

Usage

1
tree_sum(el, values)

Arguments

el

[character data.frame] The edgelist specifying the tree structure. The first column are character names for the parents, the second are children.

values

[named vector] Tip values on which to aggregate. The names must be the same names as in el.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
el <- data.frame(
  parent = c("1", "1","2", "2", "2"),
  child = c("2", "7", "3", "4", "5"),
  stringsAsFactors = FALSE
)
counts  <- c(
  "7" = 10,
  "3" = 2,
  "4" = 5,
  "5" = 1
)
tree_sum(el, counts)

krisrs1128/treelapse documentation built on Jan. 3, 2020, 6:29 p.m.