Determines how each variable is summarized: "continuous" (one line of
statistics), "continuous2" (one line per statistic), "categorical" (one
line per level) or "dichotomous" (one line showing a single level). The
rules follow gtsummary: a user-specified type wins; a variable with a
value is dichotomous; logicals, 0/1 numerics and two-level
yes/no variables are dichotomous; factors and characters are categorical;
numeric, date and time variables with fewer than cat_threshold distinct
values are categorical and otherwise continuous. Continuous variables get
the type "continuous" unless options(ltsummary.default_con_type = "continuous2") is set.
Usage
assign_summary_type(
data,
variables,
value,
type = NULL,
cat_threshold = getOption("ltsummary.cat_threshold", 10L)
)Arguments
- data
(
data.frame)
A data frame.- variables
(
character)
Variables to assign a type to.- value
(named
list)
Values for dichotomous variables, keyed by variable name.- type
(named
list)
User-specified types, keyed by variable name.- cat_threshold
(
integer)
Numeric variables with fewer than this many distinct non-missing values are treated as categorical. The default can be set withoptions(ltsummary.cat_threshold = ).
See also
Other summary engine:
assign_summary_digits()
Examples
assign_summary_type(
data = trial,
variables = c("age", "grade", "response"),
value = NULL
)
#> $age
#> [1] "continuous"
#>
#> $grade
#> [1] "categorical"
#>
#> $response
#> [1] "dichotomous"
#>
# a numeric variable with few distinct values is categorical by default
assign_summary_type(data.frame(x = rep(1:3, 10)), "x", value = NULL)
#> $x
#> [1] "categorical"
#>
assign_summary_type(data.frame(x = rep(1:3, 10)), "x", value = NULL, cat_threshold = 3L)
#> $x
#> [1] "continuous"
#>