Methods to extract and replace index values like a matrix.
# S3 method for piar_index
[(x, i, j, ...)# S3 method for piar_index
[(x, i, j, ...) <- value
A price index that inherits from the same class as x.
A price index, as made by, e.g., elemental_index().
Indices for the levels and time periods of a price index. See details.
Not currently used.
A numeric vector or price index. See 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.
Other index methods:
aggregate.piar_index,
as.data.frame.piar_index(),
as.ts.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(),
window.piar_index()
index <- as_index(matrix(1:6, 2))
index["1", ]
index[, 2]
index[1, ] <- 1 # can be useful for doing specific imputations
index
Run the code above in your browser using DataLab