Learn R Programming

rapportools (version 1.1)

rp.desc: Descriptive Statistics

Description

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.

Usage

rp.desc(
  measure.vars,
  id.vars = NULL,
  fn,
  data = NULL,
  na.rm = FALSE,
  margins = TRUE,
  total.name = "Total",
  use.labels = getOption("rapport.use.labels")
)

Arguments

measure.vars

either a character vector with variable names from data, a numeric vector, or a data.frame

id.vars

same rules apply as in measure.vars, but defaults to NULL

fn

a list with functions or a character vector with function names

data

a data.frame holding variables specified in id.vars and measure.vars

na.rm

a logical value indicating whether NA values should be removed

margins

should margins be included?

total.name

a character string with name for "grand" margin (defaults to "Total")

use.labels

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.

Value

a data.frame with aggregated data

Examples

Run this code
# NOT RUN {
rp.desc("cyl", NULL, c(mean, sd), mtcars)
rp.desc("cyl", "am", c(mean, sd), mtcars, margins = TRUE)
rp.desc("hp", c("am", "gear"), c("Average" = mean, "Deviation" = sd), mtcars)
# }

Run the code above in your browser using DataLab