Другим вариантом может быть использование knitr
library(janitor)
library(tidyverse)
library(kableExtra)
library(knitr)
sample.df %>%
tabyl(Role, Sex) %>%
adorn_totals(where=c("row", "col")) %>%
# Part 2
mutate(type=case_when(
Role %in% c('Father', 'Mother') ~ 'parent',
Role %in% c('Proband', 'Sibling') ~ 'child',
TRUE ~ ''
)) %>%
group_by(type) %>%
mutate(total=sum(Total)) %>%
ungroup() %>%
kable("html") %>%
kable_styling(c("striped", "bordered")) %>%
collapse_rows(columns = c(5,6))
Вывод:
Пример данных:
sample.df <- structure(list(Seq_ID = c("SSC02219", "SSC02217", "SSC02254",
"SSC02220", "SSC02184", "SSC02181", "SSC02178", "SSC03092", "SSC03078",
"SSC03070"), Family = c(11000L, 11000L, 11000L, 11000L, 11001L,
11001L, 11001L, 11002L, 11002L, 11002L), Father = c("0", "0",
"SSC02219", "SSC02219", "0", "0", "SSC02184", "0", "0", "SSC03092"
), Mother = c("0", "0", "SSC02217", "SSC02217", "0", "0", "SSC02181",
"0", "0", "SSC03078"), Sex = c("Male", "Female", "Male", "Female",
"Male", "Female", "Male", "Male", "Female", "Female"), Role = c("Father",
"Mother", "Proband", "Sibling", "Father", "Mother", "Proband",
"Father", "Mother", "Proband"), Type = c("Parent", "Parent",
"Child", "Child", "Parent", "Parent", "Child", "Parent", "Parent",
"Child")), row.names = c("1", "2", "3", "4", "5", "6", "7", "8",
"9", "10"), class = c("tbl_df", "tbl", "data.frame"))