Convert a wide-form vector (e.g., indicators or multipliers) into long form,
which is often more useful for printing or joining. This is a thin wrapper
around tidyr::pivot_longer(), provided so you do not need to load tidyr
explicitly.
Usage
vector_transpose_longer(
data_table,
names_to = "nace_r2",
values_to = "value",
key_column_name = NULL,
.keep = FALSE
)
vector_transpose(
data_table,
names_to = "nace_r2",
values_to = "value",
key_column_name = NULL,
.keep = FALSE
)Arguments
- data_table
A
data.frameor tibble. The first column is assumed to be a key column.- names_to
Name of the new column containing previous column names. Default:
"nace_r2".- values_to
Name of the new column containing the values. Default:
"value".- key_column_name
Optional. New name for the first (key) column. If
NULL(default), the name is not changed.- .keep
Logical. If
TRUE, keep the indicator identifier column. IfFALSE(default), drop it.
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(),
rows_add(),
supplementary_add(),
total_tax_add(),
vector_transpose_wider()
Examples
vector_transpose_longer(
data.frame(
indicator = "my_indicator",
agriculture = 0.0123,
manufacturing = 0.1436,
trade = 0.0921
)
)
#> # A tibble: 3 × 2
#> nace_r2 value
#> <chr> <dbl>
#> 1 agriculture 0.0123
#> 2 manufacturing 0.144
#> 3 trade 0.0921
# Keep the indicator column
vector_transpose_longer(
data.frame(
indicator = "my_indicator",
agriculture = 0.0123,
manufacturing = 0.1436
),
.keep = TRUE
)
#> # A tibble: 2 × 3
#> indicator nace_r2 value
#> <chr> <chr> <dbl>
#> 1 my_indicator agriculture 0.0123
#> 2 my_indicator manufacturing 0.144
