#学习table 1的做法以及转成word
#读入模拟数据data_sim
mydata_sim
header = TRUE)
#View(mydata_sim)
#head(mydata_sim)
Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jre1.8.0_171")
#加载'Tableone'的包
library(tableone)
#看看数据中有哪些列名
names(mydata_sim)
#选出你想要显示的变量
list_var
#找出因子化变量
cat_var
#1.做总表
table1
table1
#根据Gender分组以后比较
list_var2
table1
table1
#把table2转换为word文档
#复制下面这段代码
table1
# Load the packages
library(ReporteRs)
library(magrittr)
# The script
doc = docx()
# add.rownames = TRUE )
flextable = FlexTable(table1,
add.rownames = TRUE )
#flextable = setZebraStyle(flextable, odd = "#DDDDDD", even = "#FFFFFF" )
doc = addFlexTable(doc, flextable)
writeDoc(doc, file = "table1.docx")
#docx() %>%
# addFlexTable(table1 %>%
# add.rownames = TRUE ) %>%
# setZebraStyle( odd = "#DDDDDD", even = "#FFFFFF" ) ) %>%
# writeDoc(file = "table1.docx")
参考:
https://www.r-bloggers.com/table-1-and-the-characteristics-of-study-population/
https://www.jianshu.com/p/7df62865c3ed
https://ask.hellobi.com/blog/datasharing/7144
领取专属 10元无门槛券
私享最新 技术干货