knitr::opts_chunk$set( collapse = TRUE, comment = NA, message =FALSE )
Function "mytable"" produce table for descriptive analysis easily. It is most useful to make table to describe baseline characteristics common in medical research papers.
If you are unfamiliar to package moonBook and mytable function, please see the R package moonBook
vignette at: https://CRAN.R-project.org/package=moonBook/vignettes/moonBook.html
You can use mytable
function to explore a data.frame.
require(moonBook) require(ztable) require(magrittr) options(ztable.type="html") mytable(acs)
You can use formula without grouping variable(s).
mytable(~age+sex,data=acs)
You can compress
mytable. If rows dealing with categorical variables have two unique values, it can be printed in a single row rather than three rows.
mytable(Dx~sex,data=acs)
mytable(Dx~sex,data=acs) %>% compress
The default representative group is the second group. If you want the first group to being representative group,
please use the no
argument.
mytable(Dx~sex,data=acs) %>% compress(no=1)
Sometimes it is more simple to omit the representative group name. You can do this by set the add.label argument FALSE.
mytable(Dx~cardiogenicShock+DM+obesity+HBP,data=acs) %>% compress
mytable(Dx~cardiogenicShock+DM+obesity+HBP,data=acs) %>% compress(add.label=FALSE)
You can print mytable object in 'html5' or 'LaTex' format with ztable.
mytable(Dx~cardiogenicShock+DM+obesity+HBP,data=acs) %>% compress(add.label=FALSE) %>% ztable
You can delete rows of an object of class mytable.
mytable(sex~Dx,data=acs)
If you want to delete the second row, use the deleteRows() function.
mytable(sex~Dx,data=acs) %>% deleteRows(2)
You can delete rows of an object of class cbind.mytable.
mytable(sex+HBP~age+Dx,data=acs) %>% deleteRows(3)
You can select method for categorical variables with catMethod
argument. Possible values are :
You can see which tests are used if you set show.all
argument of mytable TRUE.
mytable(obesity~HBP,data=acs,catMethod=1,show.all=TRUE)
Sometimes, you want to display formatted numbers. For example, 1234.5
can be printed as 1,234.5
.
You can do this using addComma() function
data(diamonds,package="ggplot2") mytable(diamonds) %>% addComma
Also you can print this in 'html5' or 'LaTex' format with ztable.
mytable(cut~.,data=diamonds) %>% addComma %>% ztable
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.