Aggregate table of descriptives according to functions
provided in fn argument. This function follows
melt/cast approach used in reshape package. Variable
names specified in measure.vars argument are treated
as measure.vars, while the ones in id.vars
are treated as id.vars (see
melt.data.frame for details). Other
its formal arguments match with corresponding arguments for
cast function. Some post-processing
is done after reshaping, in order to get pretty row and
column labels.
rp.desc(measure.vars, id.vars = NULL, fn, data = NULL, na.rm = TRUE,
margins = NULL, subset = TRUE, fill = NA, add.missing = FALSE,
total.name = "Total", varcol.name = "Variable",
use.labels = getOption("rapport.use.labels"), remove.duplicate = TRUE)either a character vector with
variable names from data, a numeric vector, or a
data.frame
same rules apply as in
measure.vars, but defaults to NULL
a list with functions or a character vector with function names
a data.frame holding variables
specified in id.vars and measure.vars
a logical value indicating whether NA
values should be removed
should margins be included? (see
documentation for eponymous argument in
melt.data.frame)
a logical vector to subset the data before aggregating
value to replace missing level combinations
(see documentation for eponymous argument in
melt.data.frame)
show missing level combinations
a character string with name for "grand" margin (defaults to "Total")
character string for column that
contains summarised variables (defaults to
"Variable")
use labels instead of variable names in
table header (handle with care, especially if you have
lengthy labels). Defaults to value specified in
rapport.use.labels option.
should name/label of the variable
provided in measure.vars be removed from each
column if only one measure.var is provided
(defaults to TRUE)
a data.frame with aggregated data
# NOT RUN {
rp.desc("cyl", "am", c(mean, sd), mtcars, margins = TRUE)
## c
rp.desc("hp", c("am", "gear"), c("Average" = mean, "Deviation" = sd),
mtcars, remove.duplicate = FALSE)
# }
Run the code above in your browser using DataLab