Skip to contents

This function adds a column of character placeholders to a data frame based on the values of from and to columns. 1-to-1 links are given unit weight placeholders, and 1-to-many links are given fractional weight placeholders.

Usage

add_placeholder_weights(df, from, to, weights_into = "weights_{{from}}")

Arguments

df

A data frame.

from

The name of the column containing source category values.

to

The name of the column containing target category values.

weights_into

The name to use for the column containing the weights placeholders. Default is "weights_from".

Value

A data frame with a new numeric column containing the weights placeholders.

See also

add_weights to generate valid crossmap weights.

Examples

mock$xmap_abc |>
  as.data.frame() |>
  add_placeholder_weights(from = upper, to = lower)
#> # A tibble: 6 × 4
#>   lower upper share weights_upper
#>   <chr> <chr> <dbl>         <dbl>
#> 1 a     AA      1               1
#> 2 b     BB      1              NA
#> 3 c     BB      1              NA
#> 4 d     CC      0.3             1
#> 5 d     DD      0.6             1
#> 6 d     EE      0.1             1