Skip to contents

This function summarizes the composition of each target to category in a set of from, to, weight links. If a data.frame of links is provided, crossmap properties are not checked. This can be useful when combined with add_placeholder_weights() to highlight where weights must be chosen.

Usage

summary_by_target(links, ...)

# S3 method for data.frame
summary_by_target(
  links,
  from,
  to,
  weights,
  parts_into = "parts",
  collapse = "+",
  na_placeholder = "___",
  frac_formula = "{from}*{weights}",
  unit_formula = "{from}",
  warn = TRUE
)

# S3 method for xmap_df
summary_by_target(
  links,
  parts_into = "parts",
  collapse = "+",
  frac_formula = "{from}*{weights}",
  unit_formula = "{from}"
)

Arguments

links

A data frame or xmap_df.

from, to

Columns in x specifying the source and target nodes

weights

Column in x specifying the weight applied to data passed along the directed link between source and target node

parts_into

A string specifying the new column to pass the summarised composition into. Default is "parts".

collapse

A string specifying the separator to use when collapsing the unit values. Default is "+".

frac_formula

A glue formula specifying how to calculate the fraction of each target value using the weighting variable. Default is "{from}*{weights}".

unit_formula

A glue formula specifying how to calculate the unit of each target value using the weighting variable. Default is "{from}".

na_placeholder.

A string character to replace NA weights with.

Value

A tibble summarizing the composition of each target value based on the weighting variable.

Examples


mock$xmap_abc |> 
  summary_by_target()
#> # A tibble: 5 × 2
#>   upper parts 
#>   <chr> <glue>
#> 1 AA    a     
#> 2 BB    b+c   
#> 3 CC    d     
#> 4 DD    d     
#> 5 EE    d     

df <- data.frame(
  parent = c("A", "A", "A", "B", "B", "B", "C"),
  child = c("x", "y", "z", "x", "y", "z", "k")
)
df |>
  add_placeholder_weights(from = parent, to = child, weights_into = "weights") |>
  summary_by_target(from = parent, to = child, weights = weights,
                    frac_formula = "{from}*{weights}")
#> Warning: Summary completed without verifying crossmap properties.
#>  To silence set `warn = FALSE`
#> # A tibble: 4 × 2
#>   child parts      
#>   <chr> <glue>     
#> 1 k     C          
#> 2 x     A*___+B*___
#> 3 y     A*___+B*___
#> 4 z     A*___+B*___