knitr::opts_chunk$set(echo = TRUE,comment = NA,message=FALSE,warning=FALSE,fig.width=6,fig.height = 6, fig.align='center',out.width="70%")
You can make tables summarizing descriptive statistics easily with webr package.
You have to install the latest versions of "webr" and "moonBook" packages from github.
if(!require(devtools)) install.packages("devtools") devtools::install_github("cardiomoon/webr") devtools::install_github("cardiomoon/moonBook") # For examples devtools::install_github("cardiomoon/rrtable") # For reproducible research
require(webr) require(moonBook) # For data acs
You can summmarize the frequencies easily with freqSummary() function. Also you can make a table summarizng frequencies with freqTable() function.
freqSummary(acs$Dx) freqTable(acs$Dx)
The freqTable() function returns an object of class "flextable". With this object, you can make html, pdf, docx, pptx file easily.
result=freqTable(acs$Dx) class(result)
You can make the frequency table for a continuous variable. In this time, you can get a long table.
freqTable(mtcars$mpg)
You can make a table summarizing the independency of two categorical variables.
x2Table(acs,Dx,sex)
You can make a table with columnwise percentages.
x2Table(acs,Dx,sex,margin=2)
You can hide pecentages.
x2Table(acs,Dx,sex,show.percent=FALSE)
You can make a numerical summary table with numSummary() function. If you use the numSummary() function to a continuous vector, you can get the following summary. This function uses psych::describe function
require(dplyr) numSummary(acs$age) numSummaryTable(acs$age)
You can make a numerical summary of a data.frame. The numSummary function uses is.numeric function to select numeric columns and make a numeric summary.
numSummary(acs) numSummaryTable(acs)
You can use dplyr::select() function to select variables to summarize.
acs %>% select(age,EF) %>% numSummary acs %>% select(age,EF) %>% numSummaryTable
You can use dplyr::group_by() and dplyr::select() function to select variables to summarize by group.
acs %>% group_by(sex) %>% select(age,EF) %>% numSummary acs %>% group_by(sex) %>% select(age,EF) %>% numSummaryTable
You can summarize by multiple groups.
acs %>% group_by(sex,Dx) %>% select(age,EF) %>% numSummary acs %>% group_by(sex,Dx) %>% select(age,EF) %>% numSummaryTable
You can use package rrtable
for reproducible research.
require(rrtable) type=c("table","table") title=c("Frequency Table","Numerical Summary") code=c("freqTable(acs$Dx)","acs %>% group_by(sex) %>% select(EF,age) %>% numSummaryTable") data=data.frame(type,title,code,stringsAsFactors = FALSE) data2pptx(data) data2docx(data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.