I have been trying to open data that I have saved in an excel spread sheet. I saved it as a csv. Then I tried using the read.csv command. However, everytime I do this-- diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header = TRUE, fill= TRUE)-- I get an error message: Error in file(file, "r") : unable to open connection In addition: Warning message: cannot open file 'M:/sloan/R/disease/disease.csv' What am I doing wrong or what should I look for to correct this? Sloan -- _______________________________________________ Surf the Web in a faster, safer and easier way: Download Opera 8 at http://www.opera.com
On Mon, 12 Sep 2005, sloan jones wrote:> I have been trying to open data that I have saved in an excel spread sheet. I saved it as a csv. Then I tried using the read.csv command. However, everytime I do this-- > > diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header = TRUE, fill= TRUE)-- > > I get an error message: > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file 'M:/sloan/R/disease/disease.csv' > > What am I doing wrong or what should I look for to correct this? >Try using file.choose() instead of typing in your file name - read.csv() cannot find a file with that name in that directory.> Sloan > >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
"sloan jones" <sledepi at operamail.com> writes:> I have been trying to open data that I have saved in an excel spread sheet. I saved it as a csv. Then I tried using the read.csv command. However, everytime I do this-- > > diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header = TRUE, fill= TRUE)-- > > I get an error message: > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file 'M:/sloan/R/disease/disease.csv' > > What am I doing wrong or what should I look for to correct this?First (must be said) check that you got the filename right... If the name is right: Did you close Excel before trying to read the file? Sometimes Windows applications hang onto their files and prevent others from opening them. Can you open it in other applications? The read.csv call looks a little odd -- you shouldn't need extra arguments, just read.csv or read.csv2 depending on locale. However, that shouldn't cause that sort of error message. -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Sloan, You don't need to save xls as csv. Actually, R reads data in excel very well. Following code is cutted from my blog and HTH. library(RODBC); ########################################################### # 1. READ DATA FROM EXCEL INTO R # ########################################################### xlsConnect<-odbcConnectExcel("C:\\temp\\demo.xls"); demo<-sqlFetch(xlsConnect, "Sheet1"); odbcClose(xlsConnect); rm(demo); On 9/12/05, sloan jones <sledepi@operamail.com> wrote:> > I have been trying to open data that I have saved in an excel spread > sheet. I saved it as a csv. Then I tried using the read.csv command. > However, everytime I do this-- > > diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header = > TRUE, fill= TRUE)-- > > I get an error message: > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file 'M:/sloan/R/disease/disease.csv' > > What am I doing wrong or what should I look for to correct this? > > Sloan > > -- > _______________________________________________ > Surf the Web in a faster, safer and easier way: > Download Opera 8 at http://www.opera.com > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- WenSui Liu (http://statcompute.blogspot.com) Senior Decision Support Analyst Cincinnati Children Hospital Medical Center [[alternative HTML version deleted]]
Sloane, try, diseasedat<-read.csv("M:\\sloan\\R\\disease\\disease.csv") and read http://cran.r-project.org/doc/manuals/R-data.html JC On Mon, 2005-09-12 at 19:58 +0100, sloan jones wrote:> I have been trying to open data that I have saved in an excel spread sheet. I saved it as a csv. Then I tried using the read.csv command. However, everytime I do this-- > > diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header = TRUE, fill= TRUE)-- > > I get an error message: > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file 'M:/sloan/R/disease/disease.csv' > > What am I doing wrong or what should I look for to correct this? > > Sloan >[[alternative HTML version deleted]]
Alternatively, you can set the working directory to your folder: File > Change dir... Select your directory, and then: diseasedat <- read.csv("disease.csv") Murray -----Original Message----- From: John Charles Considine [mailto:vinum at iinet.net.au] Sent: Tuesday, 13 September 2005 9:29 AM To: r-help Subject: Re: [R] trouble with reading data from excel Sloane, try, diseasedat<-read.csv("M:\\sloan\\R\\disease\\disease.csv") and read http://cran.r-project.org/doc/manuals/R-data.html JC On Mon, 2005-09-12 at 19:58 +0100, sloan jones wrote:> I have been trying to open data that I have saved in an excel spread sheet. I saved it as a csv. Then I tried using the read.csv command. However, everytime I do this-- > > diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header = TRUE, fill= TRUE)-- > > I get an error message: > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file 'M:/sloan/R/disease/disease.csv' > > What am I doing wrong or what should I look for to correct this? > > Sloan >[[alternative HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Hi On 12 Sep 2005 at 15:23, Wensui Liu wrote:> Sloan, > > You don't need to save xls as csv. Actually, R reads data in excel > very well. Following code is cutted from my blog and HTH. > > library(RODBC); > > ########################################################### > # 1. READ DATA FROM EXCEL INTO R # > ########################################################### > xlsConnect<-odbcConnectExcel("C:\\temp\\demo.xls"); > demo<-sqlFetch(xlsConnect, "Sheet1"); > odbcClose(xlsConnect); > rm(demo);or if you are on Windows open Excel select what you want to read, including header press ctrl-C in R mydata<-read.delim("clipboard") to write from R write.table(tab, "clipboard", sep = "\t", row.names = F) open Excel press ctrl-V HTH Petr> > > On 9/12/05, sloan jones <sledepi at operamail.com> wrote: > > > > I have been trying to open data that I have saved in an excel spread > > sheet. I saved it as a csv. Then I tried using the read.csv command. > > However, everytime I do this-- > > > > diseasedat<-read.csv("M:/sloan/R/disease/disease.csv", sep=, header > > = TRUE, fill= TRUE)-- > > > > I get an error message: > > > > Error in file(file, "r") : unable to open connection > > In addition: Warning message: > > cannot open file 'M:/sloan/R/disease/disease.csv' > > > > What am I doing wrong or what should I look for to correct this? > > > > Sloan > > > > -- > > _______________________________________________ > > Surf the Web in a faster, safer and easier way: > > Download Opera 8 at http://www.opera.com > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > -- > WenSui Liu > (http://statcompute.blogspot.com) > Senior Decision Support Analyst > Cincinnati Children Hospital Medical Center > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz