Description Usage Arguments Details Value Author(s) See Also Examples
This function computes useful summary statistics from a data frame of numbers and factors into what many call a "Table 1" for many clinical research reports used to describe the study population. It can also be used to construct comparison tables for treatment groups or other strata.
1 | produce.table1(x, labels = NULL)
|
x |
a data frame of patient characteristics from a study. All components in x are assumed to be numeric or factors. |
labels |
a list of reference values to use for factor variables. If NULL reports the most prevalent group as the referenced group. It will specify which group in the table. |
This function computes mean and standard deviations for numeric columns and number of individuals with a characteristic along with percentage for factor columns contained in a data.frame. Outputs a matrix of characters which can then be passed to some other functions for display in a research report.
See the tableone
package for a more comprehensive function that has many other bells and whistles.
a character matrix of 1 column with means and standard deviations calculated for numeric columns and N and
Jesse D. Raffa
1 2 3 4 5 6 7 8 9 10 11 12 | require(knitr)
set.seed(1)
N <- 100;
dataf <- data.frame(age=runif(N,0,100),sex=sample(c("M","F"),N,replace=TRUE),cholesterol=rnorm(N,100,30))
out <- produce.table1(dataf,labels=c(NA,"F",NA))
kable(out)
dfbysex <- split(dataf,dataf$sex)
out1 <- produce.table1(dfbysex[[1]])
out2 <- produce.table1(dfbysex[[2]],labels=attr(out1,"labels"))
outbysex <- cbind(out1,out2)
colnames(outbysex) <- paste(colnames(outbysex), c(as.character(dfbysex[[1]]$sex[1]),as.character(dfbysex[[2]]$sex[1])))
kable(outbysex)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.