summarize: Compute summary statistics

Description Usage Arguments Value Examples

View source: R/summarize.R

Description

Compute summary statistics (similar to the SAS macro procmean). This is essentially an interface to the stats::aggregate function.

Usage

1
2
3
4
5
6
7
summarize(
  formula,
  data,
  na.action = stats::na.pass,
  na.rm = FALSE,
  which = c("observed", "missing", "mean", "sd", "min", "median", "max")
)

Arguments

formula

[formula] on the left hand side the outcome(s) and on the right hand side the grouping variables. E.g. Y1+Y2 ~ Gender + Gene will compute for each gender and gene the summary statistics for Y1 and for Y2. Passed to the stats::aggregate function.

data

[data.frame] dataset (in the wide format) containing the observations.

na.action

[function] a function which indicates what should happen when the data contain 'NA' values. Passed to the stats::aggregate function.

na.rm

[logical] Should the summary statistics be computed by omitting the missing values.

which

[character vector] name of the summary statistics to kept in the output. Can be any of, or a combination of: "observed" (number of observations with a measurement), "missing" (number of observations with a missing value), "mean", "sd", "min", "median", "max".

Value

a data frame containing summary statistics (in columns) for each outcome and value of the grouping variables (rows).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## simulate data in the wide format
set.seed(10)
d <- sampleRem(1e2, n.times = 3)

## add a missing value
d2 <- d
d2[1,"Y2"] <- NA

## run summarize
summarize(Y1+Y2 ~ 1, data = d)
summarize(Y1+Y2 ~ X1, data = d)

summarize(Y1+Y2 ~ X1, data = d2)
summarize(Y1+Y2 ~ X1, data = d2, na.rm = TRUE)

## End of examples

LMMstar documentation built on Nov. 5, 2021, 1:07 a.m.