Learn R Programming

iotables (version 0.9.4)

rows_add: Add Conforming Row(s) to an Input–Output Table

Description

Add a conforming row, or elements of a conforming row, to a named input–output style data frame.

Usage

rows_add(data_table, rows_to_add, row_names = NULL, empty_fill = 0)

Value

A data.frame containing the original data_table extended with the new row(s).

Arguments

data_table

A symmetric input–output table, a use table, a margins table, or a tax table retrieved by iotable_get().

rows_to_add

A data frame or a named numeric vector containing the new row(s).

row_names

Optional character vector giving names for the new key column. If NULL, names are inferred (see Details).

empty_fill

Value used to fill missing columns. Defaults to 0.

Details

You can add rows in several ways:

  • A data frame with one or more rows, where the first column contains row identifiers.

  • A named numeric vector, which will be turned into a single-row data frame.

If no row_names are supplied and the first column of rows_to_add is numeric, new rows will be automatically labelled as "new_row_1", "new_row_2", etc.

Missing column values are filled with empty_fill, which defaults to 0. If you want to avoid division by zero in later computations, you can set this to a very small value (e.g. 1e-6).

See Also

Other iotables processing functions: conforming_vector_create(), empty_remove(), household_column_find(), household_column_get(), iotable_year_get(), key_column_create(), matrix_round(), output_get(), primary_input_get(), supplementary_add(), total_tax_add(), vector_transpose_longer(), vector_transpose_wider()

Examples

Run this code
rows_to_add <- data.frame(
  iotables_row = "CO2_emission",
  agriculture_group = 10448,
  industry_group = 558327, # construction is omitted
  trade_group = 11194
)

rows_add(iotable_get(), rows_to_add = rows_to_add)

rows_add(iotable_get(),
  rows_to_add = c(
    industry_group = 1534,
    trade_group = 4
  ),
  row_names = "CH4_emission"
)

Run the code above in your browser using DataLab