tbl_likert(
data,
statistic = ~"{n} ({p}%)",
label = NULL,
digits = NULL,
include = everything(),
sort = c("ascending", "descending")
)
(data.frame
)
A data frame.
(formula-list-selector
)
Used to specify the summary statistics for each variable.
The default is everything() ~ "{n} ({p}%)"
.
(formula-list-selector
)
Used to override default labels in summary table, e.g. list(age = "Age, years")
.
The default for each variable is the column label attribute, attr(., 'label')
.
If no label has been set, the column name is used.
(formula-list-selector
)
Specifies how summary statistics are rounded. Values may be either integer(s)
or function(s). If not specified, default formatting is assigned
via assign_summary_digits()
.
(tidy-select
)
Variables to include in the summary table. Default is everything()
.
(string
)
indicates whether levels of variables should be placed in
ascending order (the default) or descending.
a 'tbl_likert' gtsummary table
levels <- c("Strongly Disagree", "Disagree", "Agree", "Strongly Agree")
df_likert <- data.frame(
recommend_friend = sample(levels, size = 20, replace = TRUE) |> factor(levels = levels),
regret_purchase = sample(levels, size = 20, replace = TRUE) |> factor(levels = levels)
)
# Example 1 ----------------------------------
tbl_likert_ex1 <-
df_likert |>
tbl_likert(include = c(recommend_friend, regret_purchase)) |>
add_n()
tbl_likert_ex1
Characteristic
N
Strongly Disagree
Disagree
Agree
Strongly Agree
# Example 2 ----------------------------------
# Add continuous summary of the likert scores
list(
tbl_likert_ex1,
tbl_wide_summary(
df_likert |> dplyr::mutate(dplyr::across(everything(), as.numeric)),
statistic = c("{mean}", "{sd}"),
type = ~"continuous",
include = c(recommend_friend, regret_purchase)
)
) |>
tbl_merge(tab_spanner = FALSE)
Characteristic
N
Strongly Disagree
Disagree
Agree
Strongly Agree
Mean
SD