Serving the Quantitative Finance Community

 
User avatar
JTB
Topic Author
Posts: 0
Joined: August 20th, 2010, 9:28 am

Opening csv-files in R

March 9th, 2011, 5:01 pm

I have checked that getwd() equals the same directory as the csv-file I want top open in R. Eventhough, I get the error:cannot open file 'myfile.csv': No such file or directorydata<-read.csv("file=mycsv.csv",head=F,sep=","Please help.
 
User avatar
JTB
Topic Author
Posts: 0
Joined: August 20th, 2010, 9:28 am

Opening csv-files in R

March 9th, 2011, 5:42 pm

After trying many options, I have found out that I have to write the whole path name?Why?Does anybody know?Again; the setwd() is specified correctly, because when I write the command:list.files(getwd(),full.name=TRUE, all.files=TRUE)it finds the csv-file!!
 
User avatar
Hansi
Posts: 41
Joined: January 25th, 2010, 11:47 am

Opening csv-files in R

March 9th, 2011, 7:25 pm

it's data<-read.csv(file="mycsv.csv",head=F,sep=",") or jut data<-read.csv(file="mycsv.csv",head=F)Also dir() works instead of list.files.I recommend going through this, take about an hour tops: http://www.cyclismo.org/tutorial/R/
 
User avatar
JTB
Topic Author
Posts: 0
Joined: August 20th, 2010, 9:28 am

Opening csv-files in R

March 10th, 2011, 7:17 am

Thanks,but still I wonder:even though I have specified the right directory, why do I need to write the whole path name /home/......./file.csv?Why can't I just write file.csv? data<-read.csv(file=file.csv",head=F,sep=",") don't work. I have to write:data<-read.csv(file=/home/..../..../..../file.csv",head=F,sep=",")...to make it work.Why?
 
User avatar
kindlyMe
Posts: 0
Joined: February 28th, 2011, 7:20 am

Opening csv-files in R

March 10th, 2011, 7:27 am

You put the double-quote at the wrong place. write:read.csv(file="mycsv.csv",head=F,sep=",")## not thisread.csv("file=mycsv.csv",head=F,sep=",")In this case R understands that your directory name is "file=mycsv.csv" (as it is the 1st argument in the read.csv() function), ofcourse it is not there, which R shows as the error message.HTH