Maybe like this
library(dplyr,quietly = TRUE,warn.conflicts = FALSE,verbose=FALSE)
library(datasets,quietly = TRUE,warn.conflicts = FALSE,verbose=FALSE)
library(janitor,quietly = TRUE,warn.conflicts = FALSE,verbose=FALSE)
#> Warning: package 'janitor' was built under R version 4.1.2
myfun <- function(x,y) {names(x)[1] <- y ; x}
df1 <- as.data.frame(HairEyeColor)
tabs <- df1 %>% select(!where(is.numeric)) %>%
purrr::imap(~tabyl(.x) %>% adorn_pct_formatting()
%>% myfun(.y)
)
for (i in seq_along(tabs))
print(knitr::kable(tabs[[i]],format="latex"))
#>
#> \begin{tabular}{l|r|l}
#> \hline
#> Hair & n & percent\\
#> \hline
#> Black & 8 & 25.0\%\\
#> \hline
#> Brown & 8 & 25.0\%\\
#> \hline
#> Red & 8 & 25.0\%\\
#> \hline
#> Blond & 8 & 25.0\%\\
#> \hline
#> \end{tabular}
#>
#> \begin{tabular}{l|r|l}
#> \hline
#> Eye & n & percent\\
#> \hline
#> Brown & 8 & 25.0\%\\
#> \hline
#> Blue & 8 & 25.0\%\\
#> \hline
#> Hazel & 8 & 25.0\%\\
#> \hline
#> Green & 8 & 25.0\%\\
#> \hline
#> \end{tabular}
#>
#> \begin{tabular}{l|r|l}
#> \hline
#> Sex & n & percent\\
#> \hline
#> Male & 16 & 50.0\%\\
#> \hline
#> Female & 16 & 50.0\%\\
#> \hline
#> \end{tabular}
Created on 2021-12-02 by the reprex package (v2.0.1)