我想用r代码做一个markdown,但是每次都没有代码,所以在markdown文件中,只有我的代码和文本。此外,代码结构不受尊重。你知道它为什么不起作用吗?我没有找到答案......
> ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ```
>
> # Assignment
>
> ## First question
>
> We read the dataset in "data" and we make the column "date" as date
> format
>
> '''{r} data<-read.csv(file="activity.csv",header=TRUE)
> data$date<-as.Date(as.character(data$date),"%Y-%m-%d") '''
>
> ## Second question
>
> Histogram of the total number of steps taken each day
>
> '''{r} library("ggplot2")
> perday<-aggregate(data$steps,list(Date=data$date),sum)
> qplot(perday$x,main="Histogram of the total number of steps taken each
> day",xlab="Number of steps") '''
它做了与上面相同的输出。
我不明白为什么......
答案 0 :(得分:2)
代码中的问题是在创建代码块时。它应该是这样的:
```{r}
# your code here
```
with backquote`(在Windows上按Ctrl + Alt + 7 ou AltGr + 7)而不是简单引用'
创建Rmarkdown的最简单方法是使用RStudio并使用按钮或键盘快捷键插入块。在Windows上是Ctrl + Alt + i。
您的正确代码应该是
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Assignment
## First question
We read the dataset in "data" and we make the column "date" as date format
```{r}
data<-read.csv(file="activity.csv",header=TRUE)
data$date<-as.Date(as.character(data$date),"%Y-%m-%d"
```
## Second question
Histogram of the total number of steps taken each day
```{r}
library("ggplot2")
perday<-aggregate(data$steps,list(Date=data$date),sum)
qplot(perday$x,main="Histogram of the total number of steps taken each
day",xlab="Number of steps")
```