所以我遇到group_rows
中的kableExtra
函数的问题。它以前一直可以正常工作,但是最近我更新到了R和Rstudio的最新版本,它似乎产生了一些错误。几个组不适用。
这是表的样子,它缺少g和j组。
我曾尝试通过issue中的此人员手动将每一列转换为字符或因子来完成此操作,但这无法解决问题。我还尝试了多次使用group_rows
,而不是使用下面的索引。我还尝试安装kableExtra
的开发人员版本,该版本也不起作用。这是造成问题的Rmarkdown文件。
---
title: "Untitled"
output:
pdf_document:
keep_tex: true
includes:
in_header: C:/Users/Owner/Documents/Academics/Thesis/Thesis Presentation/header2.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(dplyr)
library(kableExtra)
groups <- c(3, 3, 5, 4, 3, 3, 3, 2, 3, 2, 3)
groups <- setNames(groups, c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"))
x <- data.frame(Term = c('Other', 'White', 'Black', '18 to 24', '25 to 39', '40 to 59', 'Married', 'No longer married', 'Never married', 'Living with partner', 'Missing', '0-1', '2-5', '6-10', '11+', '0-1', '2-5', '6+', '0-1', '2-5', '6+', '0-1', '2-5', '6+', 'Yes', 'No', 'Never', 'Ever', 'Missing', 'Never', 'Ever', 'Heterosexual', 'Homosexual/Bisexual', 'Other'),
uni = c('Ref', '0.87(0.36, 2.1)', '1.3(0.62, 2.7)^', 'Ref', '0.65(0.32, 1.3)', '0.69(0.38, 1.2)', 'Ref', '4.5(1.5, 13.5)**^', '3.8(1.6, 9.1)**^', '2.7(0.86, 8.3)^', '7.1(2.4, 20.7)***', 'Ref', '1.9(0.47, 7.3)^', '2.5(0.89, 6.9)^', '4.1(1.5, 11.6)**^', 'Ref', '4.2(2.2, 7.8)***', '14.1(2.6, 75.9)***^', 'Ref', '1.6(0.81, 3.1)^', '3.7(1.5, 9.2)**^', 'Ref', '2.8(1.2, 6.3)*^', '16.8(3.1, 92.5)***^', 'Ref', '0.59(0.28, 1.2)', 'Ref', '3.2(1.3, 7.9)*^', '6.6(3.3, 13.2)***', 'Ref', '2.7(1.5, 4.9)***', 'Ref', '1.4(0.48, 4.0)^', '0.69(0.16, 3.0)'),
adj = c('Ref', '0.63(0.21, 1.9)', '0.86(0.40, 1.8)', 'Ref', '1.5(0.43, 5.1)^', '2.1(0.75, 5.9)^', 'Ref', '2.5(0.73, 8.5)^', '2.8(0.79, 9.6)^', '2.0(0.62, 6.4)^', '5.9(1.0, 34.4)^', 'Ref', '0.99(0.14, 7.1)', '0.70(0.16, 3.1)', '0.57(0.11, 3.0)', 'Ref', '3.3(0.87, 12.8)^', '4.2(0.85, 20.3)^', 'Ref', '1.3(0.44, 3.8)^', '2.1(0.47, 9.6)^', 'Ref', '0.65(0.13, 3.2)', '2.6(0.54, 12.5)^', 'NA', 'NA', 'Ref', '2.3(0.81, 6.5)^', '1.8(0.31, 11.1)^', 'Ref', '1.7(0.89, 3.1)^', 'NA', 'NA', 'NA'),
uni1 = c('Ref', '1.1(0.37, 3.2)^', '0.67(0.19, 2.3)', 'Ref', '0.38(0.16, 0.89)*', '0.61(0.24, 1.5)', 'Ref', '3.5(1.0, 12.5)^', '2.4(0.84, 7.0)^', '1.7(0.34, 8.3)^', '8.0(2.5, 25.4)***', 'Ref', '1.2(0.23, 6.5)^', '2.5(0.81, 7.8)^', '4.1(1.3, 13.3)*^', 'Ref', '4.4(2.1, 9.3)***', '18.2(2.8, 120.2)***^', 'Ref', '2.9(0.96, 8.7)^', '6.0(1.9, 18.6)***^', 'Ref', '3.8(1.4, 10.4)*^', '22.5(3.2, 155.8)***^', 'Ref', '0.99(0.33, 3.0)', 'Ref', '4.8(1.8, 12.6)***^', '12.0(5.3, 27.1)***', 'Ref', '3.3(1.4, 7.9)*^', 'Ref', '0.98(0.24, 4.0)', '1.0(0.24, 4.6)^'),
adj1 = c('Ref', '0.73(0.22, 2.5)', '0.47(0.14, 1.6)', 'Ref', '0.88(0.15, 5.2)', '1.9(0.48, 7.6)^', 'Ref', '1.7(0.48, 6.0)^', '1.8(0.39, 8.0)^', '1.2(0.28, 5.5)^', '6.5(0.95, 44.8)^', 'Ref', '0.36(0.06, 2.2)', '0.41(0.09, 1.8)', '0.36(0.08, 1.7)', 'Ref', '3.2(0.45, 23.2)^', '4.6(0.55, 38.9)^', 'Ref', '3.0(0.75, 12.0)^', '3.1(0.54, 18.1)^', 'Ref', '0.95(0.11, 8.0)', '3.3(0.41, 26.8)^', 'NA', 'NA', 'Ref', '3.3(1.3, 8.1)*^', '1.9(0.27, 13.1)^', 'Ref', '1.4(0.70, 2.9)^', 'NA', 'NA', 'NA'))
```
```{r, echo = FALSE, results='asis'}
kable(x, format = "latex", longtable = T, booktabs = T, row.names = FALSE, linesep = "") %>%
kable_styling(latex_options = c("striped")) %>%
group_rows(index = groups)
```
我的头是这个
\PassOptionsToPackage{full}{textcomp}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{xtab}
\usepackage{setspace}
%% Language and font encodings
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{newtxtext,newtxmath}
%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
Your help is appreciated