matrix_table | R Documentation |

This function creates a table showing percentages and counts for each
response option in a multiple-choice question, specified by `question`

. If
grouping is provided with `group_by`

, the table is extended to include
subgroups. Subgroups can be excluded, and survey weights are supported for
adjusted counts. The table is formatted for clarity and can be displayed in
wide format. When weights are used, counts are presented as percentages only,
and a note is added at the bottom of the table.

```
matrix_table(
dataset,
question,
group_by = NULL,
subgroups_to_exclude = NULL,
weights = NULL,
na.rm = FALSE,
column_order = NULL
)
```

`dataset` |
The input dataframe (or tibble) of survey questions |

`question` |
The columns that contain each of the response options for a
question, can be selected by using |

`group_by` |
Optional variable to group the analysis. If provided, the frequencies and counts will be calculated within each subgroup. |

`subgroups_to_exclude` |
Optional vector specifying subgroups to exclude from the analysis. |

`weights` |
Optional variable containing survey weights. If provided, frequencies and counts will be weighted accordingly. |

`na.rm` |
Logical indicating whether to remove NA values from |

`column_order` |
reorder columns of final table with an argument to pass to |

A gt table summarizing percentages and counts for each response option in the specified multiple-choice question. If grouping is provided, the table includes subgroups and is formatted for clarity.

@examples #Array question (1-5) matrix_table(berlinbears, dplyr::starts_with('p_'))

#Use `group_by`

to partition the question into several groups
matrix_table(berlinbears, dplyr::starts_with('p_'), group_by = species,
subgroups_to_exclude = 'panda bear' )

#Remove NA category matrix_table(berlinbears, dplyr::starts_with('p_'), group_by = species, subgroups_to_exclude = 'panda bear', na.rm = TRUE

#Categorical input matrix_table(berlinbears, dplyr::starts_with('c_'), group_by = is_parent)

Other matrix questions:
`matrix_freq()`

,
`matrix_likert()`

,
`matrix_mean()`

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.