我想帮助有关透视表(从pivottabler)和导出到word文档(通过Rmarkdown步骤)。
在日常工作中,我将表格导出为Excel文件,但对于年度报告,我希望自动将摘要表导出为word文档,并保持格式不变。我试着用html和latex格式导出,或者把数据透视表的值转换成dataframe格式,但都不起作用。
有人能帮帮我吗?要么向我展示这个包的技术,要么告诉我其他哪些包可以很容易地在R标记中导出,我可以轻松地重现(并且相同地)我的表?
library(pivottabler)
pt <- PivotTable$new()
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC",
outlineBefore=list(isEmpty=FALSE,
groupStyleDeclarations=list(color="blue")),
outlineTotal=list(groupStyleDeclarations=list(color="blue")))
pt$addRowDataGroups("PowerType", addTotal=FALSE)
pt$addRowDataGroups("SchedSpeedMPH", addTotal=FALSE)
pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
pt$renderPivot()

发布于 2021-05-14 16:13:48
这里有一个使用R Markdown to Word的教程:https://rmarkdown.rstudio.com/articles_docx.html
一个生成Word输出的标记文件示例:
---
title: "Example Output to Word"
output: word_document
---
```{r setup, include=FALSE}knitr::opts_chunk$set(echo =真)
## Example Pivot Table
```{r}库(透视表)
pt <-数据透视表$new()
pt$addData(Bhmtrain)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC",
outlineBefore=list(isEmpty=FALSE, groupStyleDeclarations=list(color="blue")), outlineTotal=list(groupStyleDeclarations=list(color="blue")))pt$addRowDataGroups("PowerType",addTotal=FALSE)
pt$addRowDataGroups("SchedSpeedMPH",addTotal=FALSE)
pt$defineCalculation(calculationName="TotalTrains",summariseExpression="n()")
pt$renderPivot()
https://stackoverflow.com/questions/67126053
复制相似问题