[R] trouble with reading data from excel

Petr Pikal petr.pikal at precheza.cz
Tue Sep 13 16:10:11 CEST 2005


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.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list