Page 1 of 1

Opening csv-files in R

Posted: March 9th, 2011, 5:01 pm
by JTB
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.

Opening csv-files in R

Posted: March 9th, 2011, 5:42 pm
by JTB
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!!

Opening csv-files in R

Posted: March 9th, 2011, 7:25 pm
by Hansi
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/

Opening csv-files in R

Posted: March 10th, 2011, 7:17 am
by JTB
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?

Opening csv-files in R

Posted: March 10th, 2011, 7:27 am
by kindlyMe
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