如何使用R生成pdf格式的报告 [英] How to generate report in pdf format using R
问题描述
我正在尝试找到R代码,该代码将通过使用R(而不是通过R-studio)以pdf或html格式提供统计分析的输出(即回归,DOE,Gage RR).我想生成我的统计分析报告.我们可以在R中运行任何R代码来制作pdf或html文件吗?我只对图知道,
I am trying to find out the R code which will give me the output of the statistical analysis(i.e. Regression, DOE, Gage RR) in pdf or html format by using R ( Not by using R-studio). I want to generate report of my statistical analysis. Is there any R code which we can run in to the R to make pdf or html file ??. I know it for graphs only,
pdf("output.pdf")
x=rnorm(100,40,3)
y=rnorm(100,100,5)
fit=lm(y~x)
summary(fit)
plot(y)
dev.off()
这段代码为我提供了pdf格式的图形,但我需要所有拟合摘要(ANOVA)和R生成的所有信息.谢谢
This code gives me graph in pdf but I want all the summary of fit (ANOVA) and all information that R generates. Thanks
推荐答案
是的,RMarkdown/knitr是必经之路.
Yes, RMarkdown/knitr is the way to go.
有关创建pdf文档的文档,请参见此处.
See here for the documentation for creating a pdf document.
您的Rmd文件可能类似于以下内容:
Your Rmd file might look something like the following:
---
title: "Report"
author: "XXX"
date: "January 7, 2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Output
```{r}
x <- rnorm(100, 40, 3)
x
y <- rnorm(100, 100, 5)
y
fit <- lm(y ~ x)
summary(fit)
```
## Plot
```{r plot, echo=FALSE}
plot(y)
```
对于html文档,只需更改为output: html_document
.
For an html document, simply change to output: html_document
.
使用rmarkdown::render('filepath/yourfile.Rmd')
这篇关于如何使用R生成pdf格式的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!