Given a model rack, calculate boxed index summaries and put them
to a rack column. If index summaries for a subset of columns already
exist, new summaries will be appended to the existing. It is possible to
put new summaries to a separate rack column by changing id parameter.
Usage
rack_put_indices_boxed(
rack,
data = "data$x",
cols = everything(),
boxes,
na.rm = FALSE,
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.- boxes
A named list describing index boxes. Each element is a character vector listing all levels to pick for a particular box. See examples for details.
- 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 index summaries will be put to rack column named "indices_boxed". If e.g. you've already put boxed index summaries for some set of columns to "indices_boxed" 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 "indices_boxed_other".
Examples
rack_extended <-
example_seg_rack %>%
# put "Top 2" and "Top 1" indices for battery "3" to "indices_boxed"
rack_put_indices_boxed(
cols = matches("_3_"),
boxes = list(
"Top 2" = c("Strongly agree", "Somewhat agree"),
"Top 1" = c("Strongly agree")
)
) %>%
# append "Top 1" indices for battery "2" to "indices_boxed"
rack_put_indices_boxed(
cols = matches("_2_"),
boxes = list(
"Top 2" = c("Strongly agree", "Somewhat agree")
)
) %>%
# put "Top 1" indices for battery "2" to "indices_boxed_other"
rack_put_indices_boxed(
cols = matches("_2_"),
boxes = list(
"Top 1" = c("Strongly agree")
),
id = "other"
)
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}
#> ! Found 2 columns with missing or invalid labels: "weight" and "segment".
#> ℹ Replacing these labels with {.code NA_character_}