Skip to contents

Turns a long format table into a wide format

Usage

create_table_variable_x_group(
  results_table,
  analysis_key = "analysis_key",
  value_columns = c("stat", "stat_low", "stat_upp"),
  list_for_excel = FALSE
)

Arguments

results_table

results table with analysis key

analysis_key

analysis key following this description "analysis_type @/@ dependent_variable %/% dependent_variable_value @/@ independent_variable %/% independent_variable_value "

value_columns

string containing the names of the columns with the stats to export

list_for_excel

Default is FALSE, the function will return a dataframe. If set to TRUE, it will return a list of dataframe with the grouping variable as name. This format makes it easier to write excel files with different tab.

Value

a data frame in a wide format with the analysis type, analysis variable, analysis variable value and the group variable value as columns. If list_for_excel is set to TRUE, it will return a list per grouping variable.

Examples

presentresults_resultstable %>% create_table_variable_x_group("analysis_key", "stat")
#> # A tibble: 154 × 9
#>    analysis_type   analysis_var analysis_var_value `locationA %/% displaced`
#>    <chr>           <chr>        <chr>                                  <dbl>
#>  1 prop_select_one fcs_cat      low                                    0.258
#>  2 prop_select_one fcs_cat      medium                                 0.323
#>  3 prop_select_one fcs_cat      high                                   0.419
#>  4 prop_select_one rcsi_cat     low                                    0.290
#>  5 prop_select_one rcsi_cat     medium                                 0.258
#>  6 prop_select_one rcsi_cat     high                                   0.452
#>  7 prop_select_one lcs_cat      none                                   0.194
#>  8 prop_select_one lcs_cat      stress                                 0.129
#>  9 prop_select_one lcs_cat      emergency                              0.323
#> 10 prop_select_one lcs_cat      crisis                                 0.355
#> # ℹ 144 more rows
#> # ℹ 5 more variables: `locationA %/% non-displaced` <dbl>,
#> #   `locationB %/% displaced` <dbl>, `locationB %/% non-displaced` <dbl>,
#> #   locationA <dbl>, locationB <dbl>