[.piar_index {piar} | R Documentation |
Extract and replace index values
Description
Methods to extract and replace index values like a matrix.
Usage
## S3 method for class 'piar_index'
x[i, j, ...]
## S3 replacement method for class 'piar_index'
x[i, j, ...] <- value
Arguments
x |
A price index, as made by, e.g., |
i , j |
Indices for the levels and time periods of a price index. See details. |
... |
Not currently used. |
value |
A numeric vector or price index. See details. |
Details
The extraction method treats x
like a matrix of index values with
(named) rows for each level and columns for each time period in
x
. Unlike a matrix, dimensions are never dropped as subscripting
x
always returns an index object. This means that subscripting with a
matrix is not possible, and only a "submatrix" can be extracted. As x
is not an atomic vector, subscripting with a single index like x[1]
extracts all time periods for that level.
The replacement method similarly treat x
like a matrix. If value
is
an index object with the same number of time periods as x[i, j]
and
it inherits from the same class as x
, then the index values and
percent-change contributions of x[i, j]
are replaced with those for the
corresponding levels of value
. If value
is not an index, then it is
coerced to a numeric vector and behaves the same as replacing values in a
matrix. Note that replacing the values of an index will remove the
corresponding percent-change contributions (if any). Unlike extraction, it
is possible to replace value in x
using a logical matrix or a two-column
matrix of indices.
Subscripting an aggregate index cannot generally preserve the aggregation structure if any levels are removed or rearranged, and in this case the resulting index is not an aggregate index. Similarly, replacing the values for an aggregate index generally breaks consistency in aggregation, and therefore the result is not an aggregate index.
Value
A price index that inherits from chainable_piar_index
if x
is a
period-over-period index, or direct_piar_index
if x
is a
fixed-base index. If x
inherits from aggregate_piar_index
then
[
returns an aggregate index if the levels are unchanged.
See Also
Other index methods:
aggregate.piar_index()
,
as.data.frame.piar_index()
,
chain()
,
contrib()
,
head.piar_index()
,
is.na.piar_index()
,
levels.piar_index()
,
mean.piar_index()
,
merge.piar_index()
,
split.piar_index()
,
stack.piar_index()
,
time.piar_index()
,
vcov.aggregate_piar_index()
Examples
index <- as_index(matrix(1:6, 2))
index["1", ]
index[, 2]
index[1, ] <- 1 # can be useful for doing specific imputations
index