微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

summarytools dfSummary markdown 不打印可变标签

如何解决summarytools dfSummary markdown 不打印可变标签

我试图让我的变量标签打印在我的降价输出中的 dfSummary 表上。当我使用 R 控制台查看器(使用 print(method="viewer"))时,我可以获得标签列,但是当我编织降价时,标签列会下降。 使用 mtcars 数据集查看我的问题示例

knitr::opts_chunk$set(results = "asis")
library(Hmisc)
library(summarytools)
st_options(plain.ascii = FALSE,style        = "rmarkdown",footnote     = NA,subtitle.emphasis = FALSE) 
label(mtcars$gear) ="Gears"
label(mtcars$cyl) ="Cylinders"
mt<-subset(mtcars,select=c(gear,cyl))
print(dfSummary(mt,labels.col=TRUE,display.labels=TRUE),method = "render",Variable.label=TRUE)

这是降价输出中的结果表

markdown 中的表格

enter image description here

但是这就是我想要的样子,带有标签列,这是我在 RConsole 中直接输入代码时得到的:

print(dfSummary(mt,method = "viewer",Variable.label=TRUE)

使用 R 查看器的表格

enter image description here

我想在 rmarkdown 表上获取标签”列 - 任何人都可以帮助解决这个问题吗?

解决方法

使用子集时标签丢失。只需子集化之后应用标签。

此外,由于 summarytools 有自己的 label() 函数,因此您无需为此加载 Hmisc

这是我如何让它以最佳方式显示:

---
title: "Labels in dfSummary"
output: html_document
---

```{r setup,include=FALSE}
knitr::opts_chunk$set(results = "asis")
library(summarytools)
st_options(plain.ascii     = FALSE,dfSummary.style = "grid",dfSummary.graph.magnif = .75,footnote        = NA) 

```

```{r,echo=FALSE}
st_css()
```

```{r}
mt <- subset(mtcars,select=c(gear,cyl))
label(mt$gear) ="Gears"
label(mt$cyl) ="Cylinders"
print(dfSummary(mt),method = "render")
```

rendered results

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。