tbl_likert | R Documentation |
experimental
tbl_likert()
creates a summary of Likert scales following the gtsummary structure.
add_n()
adds a column to the table with the total number of observations.
add_continuous_stat()
converts Likert scales into a numeric score and computes
continuous statistics based on this score.
tbl_likert(
data,
label = NULL,
statistic = NULL,
digits = NULL,
include = everything(),
sort = c("default", "ascending", "descending")
)
## S3 method for class 'tbl_likert'
add_n(
x,
statistic = "{n}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)
add_continuous_stat(x, ...)
## S3 method for class 'tbl_likert'
add_continuous_stat(
x,
statistic = "{mean}",
digits = NULL,
col_label = NULL,
footnote = FALSE,
last = TRUE,
score_values = NULL,
stat_col_name = NULL,
...
)
data |
A data frame |
label |
List of formulas specifying variables labels,
e.g. |
statistic |
String or formula indicating the statistic to be reported.
Default is the mean score. Other possible continuous statistics are described
in |
digits |
Formula or list of formulas indicating how to display the
computed statistics, see |
include |
variables to include in the summary table. Default is |
sort |
Sort table based on mean scores? Must be one of
|
x |
Object with class |
col_label |
String indicating the column label. Default is generated
from |
footnote |
Logical argument indicating whether to print a footnote
clarifying the statistics presented. Default is |
last |
Logical indicator to include the new column last in table.
Default is |
... |
not used |
score_values |
Vector indicating the numeric value of each factor level.
Default is |
stat_col_name |
Optional string indicating the name of the new column
added to |
Example 1
Other gtsummary-related functions:
add_inline_forest_plot()
,
add_sparkline()
,
as_ggplot()
,
bold_italicize_group_labels()
,
logistic_reg_adj_diff()
,
style_tbl_compact()
,
theme_gtsummary_msk()
library(dplyr)
set.seed(1123)
likert_lvls <- c("Never", "Sometimes", "Often", "Always")
df <-
tibble::tibble(
Q1 = sample(likert_lvls, size = 100, replace = TRUE),
Q2 = sample(likert_lvls, size = 100, replace = TRUE)
) %>%
mutate(across(c(Q1, Q2), ~factor(., levels = likert_lvls)))
tbl_likert_ex1 <-
tbl_likert(df) %>%
add_n() %>%
add_continuous_stat(statistic = "{mean}") %>%
add_continuous_stat(statistic = "{sd}")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.