本文介绍了循环播放R降价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个R markdown文档,如下所示:

I have an R markdown document like this:

The following graph shows a histogram of variable x:

```{r}
hist(x)
```

我想引入一个循环,因此我可以对多个变量执行相同的操作.假设是这样的:

I want to introduce a loop, so I can do the same thing for multiple variables. Something hypothetically like this:

for i in length(somelist) {
  output paste("The following graph shows a histogram of somelist[[" , i, "]]")
  ```{r}
  hist(somelist[[i]])
  ```

那有可能吗?

PS:更大的计划是创建一个程序,该程序将遍历数据框并自动为每列生成适当的摘要(例如直方图,表格,箱形图等).然后,该程序可用于自动生成降价文档,其中包含您在查看第一个数据的数据时将进行的探索性分析.

PS: The greater plan is to create a program that would go over a data frame and automatically generates appropriate summaries for each column (e.g. histogram, tables, box plots, etc). The program then can be used to automatically generate a markdown document that contains the exploratory analysis you would do when seeing a data for the first data.

推荐答案

那是您想要的吗?

---
title: "Untitled"
author: "Author"
output: html_document
---


```{r, results='asis'}
for (i in 1:2){
   cat('\n')
   cat("#This is a heading for ", i, "\n")
   hist(cars[,i])
   cat('\n')
}
```

此答案或多或少地从此处被盗.

This answer was more or less stolen from here.

这篇关于循环播放R降价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:44