Вы можете попробовать kable
пакет
library(tidyverse)
library(kableExtra)
df <- data.frame(
matrix(c(
"None","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"R","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"I1","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"R-I1","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"I1-R","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"I1-I2","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"R-I1-I2","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"I1-R-I2","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3",
"I1-I2-R","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3","p0","p1","p2","p3"),
nrow = 9, byrow = TRUE),
stringsAsFactors = FALSE)
kable(df, col.names = rep("", ncol(df))) %>%
kable_styling() %>%
add_header_above(c("age group" = 1,"0" = 1,"1" = 1,"2" = 1,"3" = 1,"0" = 1,"1" = 1,"2" = 1,"3" = 1,
"0" = 1,"1" = 1,"2" = 1,"3" = 1,"0" = 1,"1" = 1,"2" = 1,"3" = 1)) %>%
add_header_above(c("diabetes" = 1, "Y" = 4, "N" = 4, "Y" = 4, "N" = 4)) %>%
add_header_above(c("gender" = 1, "male" = 8, "female" = 8))