Put segmentation feature counts summaries to a model rack
Source:R/make_feature_counts.R
rack_put_feature_counts.RdGiven a model rack, calculate segmentation attribute count
summaries and put them to a rack column. It is possible to put new
summaries to a separate rack column by changing id parameter.
Usage
rack_put_feature_counts(
rack,
data = "data$x",
cols = everything(),
na.rm = TRUE,
id = NULL
)Arguments
- rack
A model rack.
- 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.
- id
Sub-name of a rack column to put index summaries to. By default it's
NULLand summaries will be put to rack column named "feat_counts". If e.g. you've already put attribute count summaries for some set of columns to "feat_counts" and want to put summaries for some other substantially different columns to a different column, you can put something like "other" toidand summaries will be put to "feat_counts_other".
Examples
rack <- rack_put_feature_counts(example_seg_rack)
#> ! Found 4 columns with missing or invalid labels: "weight", "segment", "name", and "value".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 4 columns with missing or invalid labels: "weight", "segment", "name", and "value".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 4 columns with missing or invalid labels: "weight", "segment", "name", and "value".
#> ℹ Replacing these labels with {.code NA_character_}
rack$feat_counts[[1]]
#> # A tibble: 12 × 6
#> # Groups: Response Option [4]
#> `Response Option` Stat `1` `2` `3` Overall
#> <fct> <chr> <p_xlsx> <p_xlsx> <p_xlsx> <dbl>
#> 1 Strongly disagree Index [34.66] [152.6] [63.55] 100
#> 2 Strongly disagree Percentage [0.04] [0.16] [0.07] 0.102
#> 3 Strongly disagree N [45.37] [419.05] [102.7] 567.
#> 4 Somewhat disagree Index [116.02] [89.82] [104.33] 100
#> 5 Somewhat disagree Percentage [0.24] [0.19] [0.22] 0.207
#> 6 Somewhat disagree N [307.09] [498.71] [340.94] 1147.
#> 7 Somewhat agree Index [114.03] [86.94] [110.82] 100
#> 8 Somewhat agree Percentage [0.49] [0.38] [0.48] 0.434
#> 9 Somewhat agree N [632.04] [1010.85] [758.35] 2401.
#> 10 Strongly agree Index [89.45] [109.29] [92.77] 100
#> 11 Strongly agree Percentage [0.23] [0.28] [0.24] 0.257
#> 12 Strongly agree N [293.58] [752.44] [375.91] 1422.