Skip to contents

Walks each value `levels` steps up the hierarchy. Values that are not themselves nodes are first matched into the finest node that contains them, so an exact age of 37 enters the hierarchy at `[35,40)` and one more step takes it to `[30,40)`.

Usage

generalize_value(
  values,
  attribute,
  hierarchy,
  levels = 1,
  units = generalization_units()
)

Arguments

values

vector of raw values

attribute

attribute name, used to select the hierarchy

hierarchy

a "reid_hierarchy" object

levels

how many steps to climb (default 1)

units

unit strings, see [generalization_units()]

Value

a character vector the same length as `values`. A value with no matching node and no parent is returned unchanged.

Details

This is the generator's side of Issue #20: it builds the generalised column a release would contain, which is what makes it possible to *test* the matching side on data whose ground truth is known.

Examples

h <- generalization_hierarchy(data.frame(
  attribute = "AGE",
  value = c("[30,35)", "[35,40)", "[40,45)", "[45,50)"),
  parent = c("[30,40)", "[30,40)", "[40,50)", "[40,50)"),
  stringsAsFactors = FALSE
))
generalize_value(c(31, 37, 46), "AGE", h, levels = 0)
#> [1] "[30,35)" "[35,40)" "[45,50)"
generalize_value(c(31, 37, 46), "AGE", h, levels = 1)
#> [1] "[30,40)" "[30,40)" "[40,50)"