r - 当 R 说 "no such file or directory"时,如何在 R 中打开 CSV 文件?

标签 r

我有一个要在 R 中打开的 excel 文件。在将 excel 文件保存为 csv 文件或文本文件后,我尝试了这两个命令。

read.table() 或 read.csv()

我认为部分问题在于文件所在的位置。我把它保存在桌面上。我在这里想念什么?

这是R输出

In file(file, "rt") :
  cannot open file 'Rtrial.csv': No such file or directory
> help.search("read.csv")
> read.csv("Rtrial.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'Rtrial.csv': No such file or directory
> read.table("tab")

最佳答案

我的问题很简单,工作目录不是文件运行时打印的“源”目录。要解决此问题,您可以使用 getwd()setwd()使您的相对链接正常工作,或者在打开 csv 时仅使用完整路径。

print(getwd()) # Where does the code think it is?
setwd("~/Documents") # Where do I want my code to be?
dat = read.csv("~/Documents/Data Visualization/expDataAnalysis/one/ac1_survey.csv") #just make it work!

关于r - 当 R 说 "no such file or directory"时,如何在 R 中打开 CSV 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568847/

相关文章:

在 R 中使用 gsub 替换以模式开头的整个单词

java - 新的 REngine 启动并立即停止

r - 对称直方图

r - 将轮函数应用于数据帧中的每个元素

r - 管道中命名空间调用的函数的运算符优先级

r - 哪种数据类型最接近 R 中的 C 结构

r - 如果已经有一个同名的函数,则定义一个 S4 方法

r - 在 randomForest 包的 partialPlot 中使用变量名作为参数

r - 检测 R 矩阵中的相似相邻值

r - 以编程方式将字符串宽度值插入 sprintf()