stby | R Documentation |
An adaptation base R's by
function, designed to
optimize the results' display.
stby(data, INDICES, FUN, ..., useNA = FALSE)
data |
an R object, normally a data frame, possibly a matrix. |
INDICES |
a grouping variable or a list of grouping variables,
each of length |
FUN |
a function to be applied to (usually data-frame) subsets of data. |
... |
Further arguments to FUN. |
useNA |
Make NA a valid grouping value in INDICES variable(s).
Set to |
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
.
An object of classes “list” and “summarytools”, giving results for each subset.
by
, group_by
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.