Skip to contents

Given a rack shelf, or in other words, row of a model rack, calculate detailed index summary. Detailed is opposed to "boxed" summary (shelf_make_indices_boxed()). In the detailed summary we do not merge response options into boxes, but rather calculate stats for each level separately. Result is returned in a form of a dataframe.

Usage

shelf_make_indices_detailed(shelf, data, cols = everything(), na.rm = FALSE)

Arguments

shelf

A rack shelf, or in other words, a row of a model rack extracted with rack_extract_shelf().

data

One of the following:

  • "data$x" to use model features for indices

  • A name of a column containing dataframe to use its columns for indices

  • a dataframe to take index columns from

cols

A tidyselect expression to subset columns from data. By default is everything() so all columns are taken.

na.rm

Drop NA categories before calculating percentages? Default is FALSE.

Examples

# Calculate indices for all columns in the "demo" element of the shelf
shelf_make_indices_detailed(example_seg_shelf, "demo", everything())
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> # A tibble: 2 × 5
#>   grp_var grp_var_label sbj_var  sbj_var_label stats             
#>   <chr>   <chr>         <chr>    <chr>         <list>            
#> 1 segment NA            s_age    Age group     <tibble [12 × 12]>
#> 2 segment NA            s_gender Gender        <tibble [6 × 12]> 

# this is equivalent
shelf_make_indices_detailed(example_seg_shelf, example_demo_data[1:100,], everything())
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> # A tibble: 2 × 5
#>   grp_var grp_var_label sbj_var  sbj_var_label stats             
#>   <chr>   <chr>         <chr>    <chr>         <list>            
#> 1 segment NA            s_age    Age group     <tibble [12 × 12]>
#> 2 segment NA            s_gender Gender        <tibble [6 × 12]>