Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中for循环的输出在RMarkdown中的顺序错误_R_R Markdown - Fatal编程技术网

R中for循环的输出在RMarkdown中的顺序错误

R中for循环的输出在RMarkdown中的顺序错误,r,r-markdown,R,R Markdown,我想在for循环中为df中的每一列打印一个绘图。我是这样做的: for (i in colnames(df)){ p <- ggplot(...) # my ggplot call print(p) } for(i在colnames(df)中){ p刚刚使用mtcars检查了一个简单的降价: --- title: "Test" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(

我想在for循环中为df中的每一列打印一个绘图。我是这样做的:

for (i in colnames(df)){
  p <- ggplot(...) # my ggplot call
  print(p)
}
for(i在colnames(df)中){

p刚刚使用mtcars检查了一个简单的降价:

---
title: "Test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
require(ggplot2)

for (i in colnames(mtcars)) {
  print(i)
  (p <- ggplot(mtcars, aes(!!rlang::sym(i))) +
    geom_bar())
}
```

也许您可以提供一个最简单的数据示例。

刚刚使用mtcars检查了一个简单的降价:

---
title: "Test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
require(ggplot2)

for (i in colnames(mtcars)) {
  print(i)
  (p <- ggplot(mtcars, aes(!!rlang::sym(i))) +
    geom_bar())
}
```

也许您可以提供一个最简单的数据示例。

您可以插入一些数据和代码以使其对我们具有可复制性吗?您的嵌套for循环应具有不同的索引变量。for(i in for)(j in…)您可以插入一些数据和代码以使其对我们具有可复制性吗?您的嵌套for循环应具有不同的索引变量。for)谢谢你的回答。如果我打电话给
print(我)
正如您所做的,我的ColName以正确的顺序输出-但绘图的顺序仍然是随机的。无法共享我的数据示例,因为它是敏感的个人数据,但结构相当于
mtcars
数据。感谢您的回答。如果我调用
print(I)
正如您所做的那样,我的ColName以正确的顺序输出-但绘图顺序仍然是随机的。由于我的数据是敏感的个人数据,因此无法共享我的数据示例,但其结构相当于
mtcars
数据。