Compute summary statistics by group

Share:

Description

groupSummary summarize continuous variables by providing means and sample standard deviations and categorical variables by giving numbers and percentages for each group.

Usage

1
groupSummary(data, group = NULL, digits = 3)

Arguments

data

a data frame contains the variables

group

a character string specify the grouping variable (default NULL)

digits

the specified number of decimal places (default 3)

Details

This function summarize continuous variables by providing means and sample standard deviations and categorical variables by giving numbers and percentages for each group. Missing values (NA) will be stripped before the computation proceeds. If you do not specify group, this function will summarize the variables for total group only.

Value

Return a data frame containing (1) means and/or numbers, (2) sample standard deviations and/or percentages, (3) numbers of available data for total and each group.

Author(s)

Yasuyuki Okumura
Department of Social Psychiatry,
National Institute of Mental Health,
National Center of Neurology and Psychiatry
yokumura@blue.zero.jp

See Also

ssd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
data(infert)
infert$case <- factor(infert$case, labels=c("control", "case"))
infert$induced <- factor(infert$induced, labels=c("0","1","2 or more"))
infert$spontaneous <- factor(infert$spontaneous, labels=c("0","1","2 or more"))

#continuous and categorical variables
groupSummary(infert, group="case")

#continuous variables only
groupSummary(infert[, c(2,3,7,8, 5)], group="case")

#categorical variables only
groupSummary(infert[, c(1,4, 6, 5)],  group="case")    

#total sample
groupSummary(infert[, c(1,4, 6, 5)])

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.