Các lệnh R thường gặp

Round number in dplyr package

options(pillar.sigfig = 4)
PlantGrowth |> dplyr:::group_by(group) |>
dplyr:::summarise(weight_mean = mean(weight))


group weight_mean
1 ctrl 5.032
2 trt1 4.661
3 trt2 5.526

Thống kê mô tả

library(table1)
library(flextable)
library(magrittr)
library(openxlsx)

table_freq <- table1:::table1.formula( ~ . | Gender,
topclass = "Rtable1-grid",
data = df)

table1:::t1flex(table_freq) %>%
flextable:::save_as_docx(path = "table_freq.docx")

openxlsx:::write.xlsx(table_freq, file = "table_freq.xlsx")

So sánh giữa hai nhóm

library(openxlsx)
library(compareGroups)

table_compare <- compareGroups:::createTable(compareGroups(VAR_Y ~ .,
data = df,
ref = 1,
riskratio = FALSE,
byrow = TRUE),
show.ratio = TRUE,
show.p.ratio = FALSE,
show.p.overall = TRUE)

compareGroups:::export2word(table_compare, file = "table_compare.docx")