knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE, comment="") library(knitr)
package to create descriptive tables
compareGroups is an R package available on CRAN which performs descriptive tables displaying means, standard deviation, quantiles or frequencies of several variables. Also, p-value to test equality between groups is computed using the appropiate test.
With a very simple code, nice, compact and ready-to-publish descriptives table are displayed on R console. They can also be exported to different formats, such as Word, Excel, PDF or inserted in a R-Sweave or R-markdown document.
You will find an extensive manual describing all compareGropus capabilities with real examples in the vignette.
Also, compareGroups package has been published in Journal of Statistical Software [Subirana et al, 2014] (https://www.jstatsoft.org/v57/i12/).
compareGroups
is developed and maintained by Isaac Subirana, Hector Sanz, Joan Vila and collaborators at the cardiovascular epidemiology research unit (URLEC), located at Barcelona Biomedical Research Park (PRBB) .
As the driving force behind the REGICOR study, URLEC has extensive experience in statistical epidemiology, and is a national reference centre for research into cardiovascular diseases and their risk factors.
Install the package from CRAN
install.packages("compareGroups")
or the lattest version from Github
library(devtools) devtools::install_github("isubirana/compareGroups")
library(compareGroups) data(regicor) tab <- descrTable(year ~ . -id , regicor, hide.no = "no", method=c(triglyc=2, tocv=2, todeath=2), sd.type = 3) export2md(tab, header.background = "black", header.color = "white", caption = "Summary by intervention group")
plot(tab["sex"], "./man/figures/var1", type="png") plot(tab["age"], "./man/figures/var1", type="png")
| | |
|:----------:|:------------:|
| plot(tab["sex"])
| plot(tab["age"])
|
| | |
data(SNPs) tabor <- descrTable(casco ~ .-id, SNPs, show.ratio=TRUE, show.p.overall=FALSE) export2md(tabor[1:4])
library(survival) regicor$tcv <- Surv(regicor$tocv, regicor$cv=="Yes") tabhr <- descrTable(tcv ~ .-id-cv-tocv, regicor, method=c(triglyc=2, tocv=2, todeath=2), hide.no="no", ref.no="no", show.ratio=TRUE, show.p.overall=FALSE) export2md(tabhr[1:10], header.label=c("p.ratio"="p-value"), caption="Descriptives by cardiovascular event")
For those not familiar to R syntax, a Web User Interface (WUI) has been implemented using Shiny tools, which can be used off line by typing cGroupsWUI()
after having compareGroups
package installed and loaded, or remotely just accessing the application hosted in a shinyapp.io server.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.