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 = "",
...
)data.frame with one row per atom, one column per name in
frames, and optionally numeric weight columns.
Ordered character vector of frame names, coarsest first.
Each must be a column of leaftable.
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.
Character vector naming the weight columns. Defaults to all numeric columns that are neither frames nor reserved names.
The weight used when a caller does not name one.
Defaults to the first entry of weights.
Optional named list giving the ordered code vocabulary per
frame. Derived from leaftable when NULL (first-appearance order).
Short name and description.
Further named entries merged into meta (e.g. source,
labels).
A NestedScale.
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.
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)