Description Usage Arguments Value Author(s) Examples
Compute and format a data frame into a table suitable for publication with means and standard deviations into parentheses.
1 |
data |
A data frame with only the columns to use to compute the mean and the standard deviation as well as the column to use to compute by group. |
grp |
Optional, the name of the column to use to compute by group. |
frq |
Optional, the name of the column to use to compute frequency tables, typically for gender. Default to NULL. |
n |
Optional, logical value to compute or not the number of observations per group. Default to TRUE. |
Return a data frame by group (if any) with the mean and the standard deviation into parentheses.
Guillaume T. Vallet gtvallet@gmail.com, University of Montreal (Canada)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Create data frame faking a group of young and elderly adults.
data = rbind(
data.frame(subject=1:10,
age=round(rnorm(10, mean=23, sd=1.5), 0),
education=round(rnorm(10, mean=15, sd=2.1), 0),
sex=sample(1:2, size=10, replace=T, prob=c(.6,.4)),
group='young'),
data.frame(subject=11:20,
age=round(rnorm(10, mean=71, sd=2), 0),
education=round(rnorm(10, mean=14, sd=1.9), 0),
sex=sample(1:2, size=10, replace=T, prob=c(.4,.6)),
group='elderly'))
# Compute the mean and standard deviation of their age and
# education. Exclude the subject column to run the function.
descTab(data[,-1], grp='group')
# Addition of the frequency table for the gender
descTab(data[,-1], grp='group', frq='sex')
# Improve the label of the gender factor
data$sex = factor(data$sex, labels=c('M','F'))
descTab(data[,-1], grp='group', frq='sex')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.