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 = FALSE,
margins = TRUE,
total.name = "Total",
use.labels = getOption("rapport.use.labels")
)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?
a character string with name for "grand" margin (defaults to "Total")
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.
a data.frame with aggregated data
rp.desc("cyl", NULL, c(mean, sd), mtcars)
#> mean sd
#> 6.187500 1.785922
rp.desc("cyl", "am", c(mean, sd), mtcars, margins = TRUE)
#> am mean sd
#> 1 0 6.947368 1.544657
#> 2 1 5.076923 1.552500
#> 3 Total 6.187500 1.785922
rp.desc("hp", c("am", "gear"), c("Average" = mean, "Deviation" = sd), mtcars)
#> am gear Average Deviation
#> 1 0 3 176.1333 47.68927
#> 2 0 4 100.7500 29.01006
#> 3 0 Total 160.2632 53.90820
#> 4 1 4 83.8750 24.17459
#> 5 1 5 195.6000 102.83385
#> 6 1 Total 126.8462 84.06232
#> 7 Total 3 176.1333 47.68927
#> 8 Total 4 89.5000 25.89314
#> 9 Total 5 195.6000 102.83385
#> 10 Total Total 146.6875 68.56287