An adaptation base R's by
function, designed to
optimize the results' display.
stby(data, INDICES, FUN, ..., useNA = FALSE)
An object of classes “list” and “summarytools”, giving results for each subset.
an R object, normally a data frame, possibly a matrix.
a grouping variable or a list of grouping variables,
each of length nrow(data)
.
a function to be applied to (usually data-frame) subsets of data.
Further arguments to FUN.
Make NA a valid grouping value in INDICES variable(s).
Set to FALSE
explicitly to eliminate message.
When the grouping variable(s) contain NA values, the
base::by
function (as well as summarytools
versions prior to 1.1.0) ignores corresponding groups. Version 1.1.0
allows setting useNA = TRUE
to make new groups using
NA values on the grouping variable(s), just as
dplyr::group_by
does.
When NA values are detected and useNA = FALSE
, a message is
displayed; to disable this message, set check.nas = FALSE
.
data("tobacco")
with(tobacco, stby(data = BMI, INDICES = gender, FUN = descr,
check.nas = FALSE))
with(tobacco, stby(data = smoker, INDICES = gender, freq, useNA = TRUE))
with(tobacco, stby(data = list(x = smoker, y = diseased),
INDICES = gender, FUN = ctable, useNA = TRUE))
Run the code above in your browser using DataLab