简体   繁体   English

无法将文件读入R

[英]Cannot read file into R

I'n a new R user and I'm trying to read my file P506A-data-time-v3.csv into R, however it responds with: 我不是R用户,我正在尝试将文件P506A-data-time-v3.csv读入R,但是它的响应为:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file '
P506A
-
data
-
time
.csv': Invalid argument

I changed the directory to the folder on my computer that the file was saved in. 我将目录更改为保存文件的计算机上的文件夹。

So I looked up other similar questions and people said to use choose.file, however I think I entered it in correctly. 因此,我查找了其他类似的问题,有人说要使用select.file,但是我认为我输入的是正确的。 The result R gave me was: R给我的结果是:

> file.choose
function (new = FALSE) 
.Internal(file.choose(new))
<bytecode: 0x07c80118>
<environment: namespace:base>
> P506A
Error: object 'P506A' not found
> -
+ data
Error in -data : invalid argument to unary operator
> -
+ timeP506A-data-time-v3<-read.table(file.choose(),header=T,sep="\t") 

Error in -timeP506A - data - time - v3 <- read.table(file.choose(), header = T,  :

  object 'timeP506A' not found

In addition: Warning message:

In read.table(file.choose(), header = T, sep = "\t") :`enter code here`

  incomplete final line found by readTableHeader on 'D:\Uni\114\Probelm Solving 

So it seems like a complicated problem too me, so any help with figuring out how to get R to read my file would be very much appreciated. 因此,对于我来说,这似乎也是一个复杂的问题,因此,非常感谢您提供任何有关如何使R读取我的文件的帮助。

Thanks 谢谢

Try the following 尝试以下

File = read.csv("P506A-data-time-v3.csv", header = TRUE)

and you can also refer the following tutorial 您还可以参考以下教程

http://www.cyclismo.org/tutorial/R/input.html#read http://www.cyclismo.org/tutorial/R/input.html#read

I had the same problem using R Studio (latest version) and with my workspace correctly set up. 使用R Studio(最新版本)并正确设置工作区时,我遇到了同样的问题。 To be precise, I had: 确切地说,我有:

file 'FILENAME.csv' has magic number 'YEAR,' Use of save versions prior to 2 is deprecated 文件“ FILENAME.csv”的魔术编号为“ YEAR”,不建议使用2之前的保存版本

So I changed the row 1 column 1 header 'YEAR' to something else, and the problem went away ! 因此,我将第1行第1列标题“ YEAR”更改为其他内容,问题就消失了!

I agree with other recommendations although here's something easier. 我同意其他建议,尽管这里有些简单。 First execute getwd(). 首先执行getwd()。 Now is that the folder where your required file is in? 现在是您所需文件所在的文件夹吗? Likely it is not. 可能不是。 Hopefully you are using R Studio. 希望您正在使用R Studio。 If so, then manually go to the bottom right panel next to the console and click files, which is at the top left of that panel. 如果是这样,请手动转到控制台旁边的右下面板,然后单击该面板左上方的文件。 Then click the the three dots "..." and go to your preferred working directory. 然后单击三个点“ ...”,然后转到您的首选工作目录。 Click Ok. 单击确定。 Then click "More" which is next to a blue wheel and just to the left of the three dots. 然后,单击蓝色轮旁边三个点左侧的“更多”。 Then select "Set as Working Directory". 然后选择“设置为工作目录”。 That's it! 而已! :) :)

very late but correct answer I have also faced this issue, this is not a big issue. 很晚但是正确的答案我也遇到了这个问题,这不是一个大问题。 You must be giving wrong file name or not giving correct extension to the file. 您必须输入错误的文件名或未提供正确的文件扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM