rmd文件导出和打开CSV文件

rmd文件导出和打开CSV文件

本文介绍了在R中使用.rmd文件导出和打开CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R格式的代码来格式化和创建要使用.rmd文件共享的数据帧.在我的代码中,我使用 write.csv file.show 创建和打开格式化数据集的CSV文件.由于我们使用.rmd来显示我编写的用于格式化的代码,因此我想知道是否有人可以在有人打开时同时运行 write.csv file.show .rmd文件?我环顾了Google和RStudio,看一看是否有可能(1)甚至有可能(2)是否有可能(如何做到),但是我什么也没发现.所以我的问题是,.rmd文件甚至能够导出和打开文件吗?如果可以,该怎么办?

I'm working on code in R that formats and creates data frames that I want to share using a .rmd file. In my code, I use write.csv and file.show to create and open CSV files of the formatted datasets. Since we are using .rmd to show the code I wrote for formatting, I was wondering if there's a way to also have write.csv and file.show run when someone opens the .rmd file? I've looked around Google and RStudio to see if 1) this is even possible and 2) if it is possible, how to do it, but I haven't found anything. So my question is, is an .rmd file even capable of exporting and opening files, and if so, how do I do it?

推荐答案

这里是一个示例.事实证明 file.show 在Rmd中不起作用,这并不奇怪.

Here is an example. It turns out file.show does not work in an Rmd, which shouldn't be too surprising.

This is  atest
========================================================

Make some data

```{r}
df <- data.frame(a=rnorm(10), b=rnorm(10))
```

Write data

```{r}
write.csv(df, "df.csv", row.names=FALSE)
```

Show the data
You will find that this does not work

```{r}
#file.show(df)
#View(df)
```

but this does
```{r}
print(df)
```

这篇关于在R中使用.rmd文件导出和打开CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 12:01