使用Rhtml创建PDF并遍历数据框

编程入门 行业动态 更新时间:2024-10-26 05:27:04
本文介绍了使用Rhtml创建PDF并遍历数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个数据帧,其中的人口统计信息分为16组.我基本上需要遍历这些组并为每个组创建一个PDF页面.我已经尝试过使用Rhtml,但到目前为止,我只能生成一页.有没有使用模板的方法?

I have a data frame that has demographic information split into 16 groups. I basically need to iterate over these groups and create a PDF page for each group. I've tried using Rhtml but so far I can only get one page to generate. Is there a way to use templates or something?

推荐答案

当需要PDF输出时,为什么不直接将.Rnw编译为.pdf?

When you need PDF output, why don't you directly compile .Rnw to .pdf?

这里是使用iris数据集的示例.它将每个物种的前几行打印在新页面上:

Here an example using the iris dataset. It prints the first few rows of each species on a new page:

\documentclass{article} \begin{document} <<results = "asis", echo = FALSE>>= library(xtable) newpage <- "" invisible(lapply(unique(iris$Species), FUN = function(x) { cat(newpage) cat(sprintf("\\section{%s}", x)) current <- head(subset(x = iris, subset = Species == x)) print(xtable(current)) newpage <<- "\\clearpage" })) @ \end{document}

我还使用了xtable来轻松获得格式正确的表.输出如下所示:

I additionally used xtable to easily get a nicely formatted table. The output looks like this:

更多推荐

使用Rhtml创建PDF并遍历数据框

本文发布于:2023-11-26 18:43:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634741.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:遍历   数据   Rhtml   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!