The general constructor. Takes a wide data.frame with one row per atom (the finest unit) and one column per frame, and returns a NestedScale.

scale_from_leaftable(
  leaftable,
  frames,
  key = NULL,
  weights = NULL,
  default_weight = NULL,
  members = NULL,
  name = "",
  desc = "",
  ...
)

Arguments

leaftable

data.frame with one row per atom, one column per name in frames, and optionally numeric weight columns.

frames

Ordered character vector of frame names, coarsest first. Each must be a column of leaftable.

key

Name of the column holding the unique atom key. Defaults to "unit" if present, otherwise the finest frame (the last entry of frames), which is copied into a unit column.

weights

Character vector naming the weight columns. Defaults to all numeric columns that are neither frames nor reserved names.

default_weight

The weight used when a caller does not name one. Defaults to the first entry of weights.

members

Optional named list giving the ordered code vocabulary per frame. Derived from leaftable when NULL (first-appearance order).

name, desc

Short name and description.

...

Further named entries merged into meta (e.g. source, labels).

Value

A NestedScale.

Details

Blank strings ("") in frame columns are normalised to NA, meaning "this atom has no code at this frame" – partial coverage is normal in real classification tables.

Examples

df <- data.frame(
  section = c("A", "A", "A", "B"),
  group   = c("A1", "A1", "A2", "B1"),
  unit    = c("A11", "A12", "A21", "B11"),
  gva     = c(100, 200, 300, 400)
)
scale_from_leaftable(df, frames = c("section", "group", "unit"))
#> NestedScale: <unnamed>
#> Frames (3, coarsest first):
#>   - section (2)
#>     - group (3)
#>       - unit (4)
#> Atoms: 4
#> Weights: gva (default: gva)