KableExtra不能很好地与tableby配合使用

KableExtra不能很好地与tableby配合使用,r,knitr,kable,kableextra,R,Knitr,Kable,Kableextra,我想在性和疾病之间做一个列联表。因为我对pdf使用R.markdown。在报告中,我使用kableExtra自定义表。当表不是data.frame时,KableExtra不能很好地创建表。所以他们用tableby 有了这个数据框,我就得到了 library(kableExtra) library(arsenal) set.seed(0) Disease<-sample(c(rep("Name of the first category of the disease",20), rep("N

我想在性和疾病之间做一个列联表。因为我对pdf使用R.markdown。在报告中,我使用
kableExtra
自定义表。当表不是data.frame时,KableExtra不能很好地创建表。所以他们用
tableby

有了这个数据框,我就得到了

library(kableExtra)
library(arsenal)
set.seed(0)
Disease<-sample(c(rep("Name of the first category of the disease",20),
rep("Name of the Second category of the disease",32),
rep("Name of the third category of the disease",48),
rep("The category of those who do not belong to the first three categories",13)))
ID<-c(1:length(Disease))
Gender<-rbinom(length(Disease),1,0.55)
Gender<-factor(Gender,levels = c(0,1),labels = c("F","M"))

data<-data.frame(ID,Gender,Disease)
库(kableExtra)
图书馆(兵工厂)
种子集(0)

疾病要避免使用knitr时将
添加到输出中,请在区块设置选项中使用results='asin',如下所示:

{r results='asis'}
通过使用print函数中的width选项,可以控制包含变量名的列的宽度。从技术上讲,您不需要在打印时包装摘要调用,但如果这样做,它不会改变任何内容,并且您可以调整宽度设置

以你为例:

print(summary(tableby(Gender~Disease)), width = 20)
当它呈现为pdf时,应该使它更具可读性。您可以更改宽度,它将按照您设置的限制进行包裹

使用示例中的代码和上面的函数调用,当编织为pdf时,该表如下所示:


您是否找到了此问题的解决方案?我的代码块设置选项中有
results=“asis”
,但我的表(输出为HTML)仍然在x变量名之前打印有
:(将
text=TRUE
添加到
summary()
中消除了s,但生成了一个连字符,该连字符作为公告点呈现在列表中,这是最接近上述答案所示的理想格式。我还尝试了
summary()的
text=
参数中的其他选项。)
,但没有任何效果。如果有任何帮助,我们将不胜感激!我上面发布的解决方案适用于pdf/latex,尽管我已经能够将summary()调用传递到as.data.frame(text=“latex”)%%>%kable(“latex”)来修改kable输出。对于html,我能够复制上面的解决方案(使用
{r results='asis}
)通过此调用:
print(摘要(tableby(性别~疾病)),宽度=45)