Skip to contents

Turn an index into a data frame or a matrix.

Usage

# S3 method for class 'piar_index'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  ...,
  contrib = FALSE,
  stringsAsFactors = FALSE
)

# S3 method for class 'piar_index'
as.matrix(x, ...)

Arguments

x

A price index, as made by, e.g., elemental_index().

row.names, stringsAsFactors

See as.data.frame().

optional

Not currently used.

...

Not currently used.

contrib

Include percent-change contributions (the default does not include them).

Value

as.data.frame() returns the index values in x as a data frame with three columns: period, level, and value. If contrib = TRUE then there is a fourth (list) column contrib containing percent-change contributions.

as.matrix() returns the index values in x as a matrix with a row for each level and a column for each time period in x.

See also

Examples

index <- as_index(matrix(1:6, 2))

as.data.frame(index)
#>   period level value
#> 1      1     1     1
#> 2      1     2     2
#> 3      2     1     3
#> 4      2     2     4
#> 5      3     1     5
#> 6      3     2     6

as.matrix(index)
#>   1 2 3
#> 1 1 3 5
#> 2 2 4 6