Many vectors (indicators, multipliers) are create in the wide form to conform matrixes in analytical functions. For binding it is more useful to have them in wide format.
Usage
vector_transpose_wider(
data_table,
names_from,
values_from,
key_column_name = NULL,
key_column_values = NULL
)
Arguments
- data_table
A matrix or vector that normally has a key column. If the key column must be created or replaced, used
key_column_name
andkey_column_values
.- names_from, values_from
A pair of arguments describing which column (or columns) to get the name of the output column (`names_from`), and which column (or columns) to get the cell values from (`values_from`).
- key_column_name
The name of the key column.
- key_column_values
You can explicitly supply key column values. Defaults to
NULL
when the key column values will be created from the long data.
Details
This is a wrapper around pivot_wider
so you do not necessarily need to
import or load the entire tidyr package.
See also
Other iotables processing functions:
conforming_vector_create()
,
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_longer()
Examples
vector_transpose_wider (data_table = germany_airpol[, -2],
names_from = 'induse',
values_from = 'value')
#> # A tibble: 9 × 9
#> airpol CPA_A `CPA_B-E` CPA_F `CPA_G-I` `CPA_J-N` `CPA_O-T` P3_S14 P1
#> <chr> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1 CO2 10448 558327 11194 71269 8792 26990 217137 904158
#> 2 CH4 1534 1160 1 4 1 1058 136 3894
#> 3 N2O 77 100 0 3 0 11 17 209
#> 4 SO2 12 1705 18 50 4 24 180 1994
#> 5 NOx 62 722 64 452 23 58 585 1967
#> 6 CO 43 1616 86 434 103 188 4198 6667
#> 7 NMVOC 20 1209 17 101 15 143 520 2024
#> 8 Dust 57 165 7 34 1 7 58 329
#> 9 Total 12252 565005 11388 72347 8939 28479 222831 921241
vector_transpose_wider (data_table = germany_airpol[1:8, 3:4],
names_from = 'induse',
values_from = 'value',
key_column_values = "CO2_emission" )
#> # A tibble: 1 × 9
#> induse CPA_A `CPA_B-E` CPA_F `CPA_G-I` `CPA_J-N` `CPA_O-T` P3_S14 P1
#> <chr> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1 CO2_emission 10448 558327 11194 71269 8792 26990 217137 904158