View source: R/colby_constructors.R
analyze | R Documentation |
Adding analyzed variables to our table layout defines the primary
tabulation to be performed. We do this by adding calls to analyze
and/or analyze_colvars
into our layout pipeline. As with adding
further splitting, the tabulation will occur at the current/next level of
nesting by default.
analyze(
lyt,
vars,
afun = simple_analysis,
var_labels = vars,
table_names = vars,
format = NULL,
na_str = NA_character_,
nested = TRUE,
inclNAs = FALSE,
extra_args = list(),
show_labels = c("default", "visible", "hidden"),
indent_mod = 0L,
section_div = NA_character_
)
lyt |
layout object pre-data used for tabulation |
vars |
character vector. Multiple variable names. |
afun |
function. Analysis function, must take |
var_labels |
character. Variable labels for 1 or more variables |
table_names |
character. Names for the tables representing each atomic
analysis. Defaults to |
format |
|
na_str |
character(1). String that should be displayed when the value of |
nested |
boolean. Should this layout instruction be applied within the
existing layout structure if possible ( |
inclNAs |
boolean. Should observations with NA in the |
extra_args |
list. Extra arguments to be passed to the tabulation function. Element position in the list corresponds to the children of this split. Named elements in the child-specific lists are ignored if they do not match a formal argument of the tabulation function. |
show_labels |
character(1). Should the variable labels for corresponding
to the variable(s) in |
indent_mod |
numeric. Modifier for the default indent position for the structure created by this function(subtable, content table, or row) and all of that structure's children. Defaults to 0, which corresponds to the unmodified default behavior. |
section_div |
character(1). String which should be repeated as a section
divider after each group defined by this split instruction, or
|
When non-NULL format
is used to specify formats for all generated
rows, and can be a character vector, a function, or a list of functions. It
will be repped out to the number of rows once this is known during the
tabulation process, but will be overridden by formats specified within
rcell
calls in afun
.
The analysis function (afun
) should take as its first parameter either
x
or df
. Which of these the function accepts changes the
behavior when tabulation is performed.
If afun
's first parameter is x, it will receive the corresponding
subset vector of data from the relevant column (from var
here) of the raw data being used to build the table.
If afun
's first parameter is df
, it will receive the
corresponding subset data.frame (i.e. all columns) of the raw data
being tabulated
In addition to differentiation on the first argument, the analysis function
can optionally accept a number of other parameters which, if and only
if present in the formals will be passed to the function by the tabulation
machinery. These are listed and described in additional_fun_params
.
A PreDataTableLayouts
object suitable for passing to further
layouting functions, and to build_table
.
None of the arguments described in the Details section
can be overridden via extra_args
or when calling
make_afun
. .N_col
and .N_total
can
be overridden via the col_counts
argument to
build_table
. Alternative values for the others
must be calculated within afun
based on a combination
of extra arguments and the unmodified values provided by the
tabulation framework.
Gabriel Becker
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
analyze("AGE", afun = list_wrap_x(summary) , format = "xx.xx")
lyt
tbl <- build_table(lyt, DM)
tbl
lyt2 <- basic_table() %>%
split_cols_by("Species") %>%
analyze(head(names(iris), -1), afun = function(x) {
list(
"mean / sd" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"),
"range" = rcell(diff(range(x)), format = "xx.xx")
)
})
lyt2
tbl2 <- build_table(lyt2, iris)
tbl2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.