我想将变量标签添加到我生成的频率表中。但是,我在summarytools 文档中找不到该功能。
这是我的代码:
数据
library(magrittr)
library(dplyr)
library(gtsummary)
library(summarytools)
require(pander)
library(knitr)
library(stringr)
data_in_na <- readr::read_table2('q1 q2
No somelongresponsethattakesupmorethanonline--somelongresponsethattakesupmorethanonline
No somelongresponsethattakesupmorethanonline--somelongresponsethattakesupmorethanonline
No somelongresponsethattakesupmorethanonline--somelongresponsethattakesupmorethanonline
No somelongresponsethattakesupmorethanonline--somelongresponsethattakesupmorethanonline
No Yes
No Always
Yes No
Yes No
Yes No
NA NA
NA NA
NA NA
NA NA
')
vct <- data_in_na %>% names(.)
产生频率的功能
create_freq <- function(v1) {
#names <- c("var name 1", "var name 2")
freq(v1,
cumul = FALSE,
totals = TRUE,
display.type = FALSE,
variable.label = v1,
missing ='missing',
report.nas = TRUE)
}
循环遍历所有变量
for (i in vct) {
tbl <- create_freq(data_in_na[i]) # build gtsummary table
print(tbl) # print table
cat('\n\n----------------------------------------------------------\n\n')
# d <- table(data_in[i])
# print(kable(d))
}
我想要的是
请问有什么建议吗??