[R] Writing a data frame in an excel file

cls59 chuck at sharpsteen.net
Mon Nov 16 21:06:05 CET 2009



anna_l wrote:
> 
> Hello, I am having trouble by using the write.table function to write a
> data frame of 4 columns and 7530 rows. I don´t  know if I should just use
> a sep="\n" and change the .xls file into a .csv file. Thanks in advance
> 


Base R cannot write .xls files by it's self.  You should output CSV using
write.csv():

  write.csv( dataFrame, file = 'results.csv' )

If you are using R on windows, then the RODBC package provides a mechanism
for dumping data frames directly to Excel files, possibly with multiple
sheets:

  require( RODBC )

  xlsFile <- odbcConnectExcel( 'results.xls', readOnly = F )

  sqlSave( xlsFile, dataFrame, tablename = 'R Results', rownames = F )

  odbcCloseAll()


The tablename argument to sqlSave allows you to assign a name to the excel
sheet that will contain the data.frame.


-Charlie

-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26378547.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list