
Get the weights for an aggregation structure
Source:R/weights.piar_aggregation_structure.R
weights.piar_aggregation_structure.RdGet and set the weights for a price index aggregation structure.
Arguments
- object
[piar_aggregation_structure]A price index aggregation structure, as made byaggregation_structure().- ...
Not currently used.
- ea_only
[logical(1)]Should weights be returned for only the elementary aggregates (the default)? Setting toFALSEgives the weights for the entire aggregation structure.- na.rm
[logical(1)]Should missing values be removed when aggregating the weights (i.e., whenea_only = FALSE)? By default, missing values are not removed.- value
[numeric >= 0]A numeric vector of weights for the elementary aggregates ofobject.
Value
weights() returns a named vector of weights for the elementary aggregates.
The replacement method replaces these values without changing the
aggregation structure. (set_weights() is an alias that's easier to use with
pipes.)
If ea_only = FALSE then the return value is a list
with a named vector of weights for each level in the aggregation structure.
See also
Other aggregation structure methods:
as.matrix.piar_aggregation_structure(),
cut.piar_aggregation_structure(),
levels.piar_aggregation_structure(),
update.piar_aggregation_structure()
Examples
# A simple aggregation structure.
# 1
# |-----+-----|
# 11 12
# |---+---| |
# 111 112 121
# (1) (3) (4)
aggregation_weights <- data.frame(
level1 = c("1", "1", "1"),
level2 = c("11", "11", "12"),
ea = c("111", "112", "121"),
weight = c(1, 3, 4)
)
pias <- as_aggregation_structure(aggregation_weights)
# Extract the weights.
weights(pias)
#> 111 112 121
#> 1 3 4
# ... or update them.
weights(pias) <- 1:3
weights(pias)
#> 111 112 121
#> 1 2 3