以Rmd格式保存Rscript
我有R脚本以Rmd格式保存Rscript,r,r-markdown,R,R Markdown,我有R脚本 mydat=read.csv("C:/Users/Admin/Downloads/test.csv", sep=";",dec=",") View(mydat) str(mydat) #deleted after FS mydat$symboling.<-NULL mydat$make.<-NULL mydat$num.of.cylinders.<-NULL mydat$fuel.type.<-NULL mydat$aspiration.<-NULL
mydat=read.csv("C:/Users/Admin/Downloads/test.csv", sep=";",dec=",")
View(mydat)
str(mydat)
#deleted after FS
mydat$symboling.<-NULL
mydat$make.<-NULL
mydat$num.of.cylinders.<-NULL
mydat$fuel.type.<-NULL
mydat$aspiration.<-NULL
mydat$num.of.cylinders.<-NULL
#this vars have small num. of obs.
mydat$engine.type.<-NULL
mydat$engine.location.<-NULL
mydat$num.of.doors.<-NULL
mydat=na.omit(mydat)
#Feature Selection
FS=Boruta(normalized.losses.~.,data=mydat)
getSelectedAttributes(FS, withTentative = F)
plot(FS, cex.axis=0.5)
#get scatterplot
scatter.smooth(x=mydat$length.,y=mydat$normalized.losses.,main="normalized losse~length")
#split sample on train and sample
index <- sample(1:nrow(mydat),round(0.70*nrow(mydat)))
train <- mydat[index,]
test <- mydat[-index,]
我不想手动写这个前缀`{r}。
是否可以使代码中由注释分隔的部分
#
#
是否以rmarkdown格式保存?
例如,在我期望的输出中
```{r}
mydat$symboling.<-NULL
mydat$make.<-NULL
mydat$num.of.cylinders.<-NULL
mydat$fuel.type.<-NULL
mydat$aspiration.<-NULL
mydat$num.of.cylinders.<-NULL
```
`{r}
mydat$symboling.您可以使用knitr
包中的spin()
函数。
它将生成一个.md
文件(但您可以使用precious=TRUE
参数保留中间.Rmd
),使用“#”chracter作为“文档参数:
doc
用于标识文档行的正则表达式;默认情况下,它遵循roxygen约定,但可以自定义,例如,如果要使用##表示文档,可以使用“^##\s*”
例如:
spin('test.R', precious = TRUE, doc = '#')
产生:
测试Rmd
您还可以看看stitch()
函数和siblings(stitch\u rhtml
和stitch\u rmd
),看看
spin('test.R', precious = TRUE, doc = '#')
```{r }
mydat=read.csv("C:/Users/Admin/Downloads/test.csv", sep=";",dec=",")
View(mydat)
str(mydat)
```
deleted after FS
```{r }
mydat$symboling.<-NULL
mydat$make.<-NULL
mydat$num.of.cylinders.<-NULL
mydat$fuel.type.<-NULL
mydat$aspiration.<-NULL
mydat$num.of.cylinders.<-NULL
```
this vars have small num. of obs.
...
```r
mydat=read.csv("C:/Users/Admin/Downloads/test.csv", sep=";",dec=",")
```
```
## Warning in file(file, "rt"): cannot open file 'C:/Users/Admin/Downloads/
## test.csv': No such file or directory
```
```
## Error in file(file, "rt"): cannot open the connection
```
```r
View(mydat)
```
...