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 ----- Anna Lippel new in R so be careful I should be asking a loooooooot of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26378240.html Sent from the R help mailing list archive at Nabble.com.
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.
hello, sep="\n" will seperate each column by \n which is not what you want. I think a csv would be the best solution. write.table(yourdataframe,sep=",") or use write.csv directly. regards, stefan On Mon, Nov 16, 2009 at 11:49:28AM -0800, 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 > > ----- > Anna Lippel > new in R so be careful I should be asking a loooooooot of questions!:teeth: > -- > View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26378240.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
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 > > ----- > Anna Lippel > new in R so be careful I should be asking a loooooooot of questions!:teeth:Excel can read CSV files, so why not just use either write.csv() or write.table() with sep=","? -Peter Ehlers
On Nov 16, 2009, at 3:06 PM, smu wrote:> hello, > > sep="\n" will seperate each column by \n which is not what you want. > > I think a csv would be the best solution. > > write.table(yourdataframe,sep=",")Excel will also read (and even prefers in some sense) tab delimited files, so: write.table(yourdataframe, file="dataout.xls", sep="\t")> or use write.csv directly. > > regards, > stefan > > On Mon, Nov 16, 2009 at 11:49:28AM -0800, 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 >> >> ----- >> Anna Lippel-->David Winsemius, MD Heritage Laboratories West Hartford, CT
On Nov 16, 2009, at 3:13 PM, David Winsemius wrote:> > On Nov 16, 2009, at 3:06 PM, smu wrote: > >> hello, >> >> sep="\n" will seperate each column by \n which is not what you want. >> >> I think a csv would be the best solution. >> >> write.table(yourdataframe,sep=",") > > Excel will also read (and even prefers in some sense) tab delimited > files, so: > > write.table(yourdataframe, file="dataout.xls", sep="\t")Neither one of those methods will deal with the problem that no separator is put in the file on the first row before the colnames. To keep the names registered with the columns you would need to set row.names=F write.table(yourdataframe, file="dataout.xls", sep="\t", row.names=FALSE) -- David.> > > >> or use write.csv directly. >> >> regards, >> stefan >> >> On Mon, Nov 16, 2009 at 11:49:28AM -0800, 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 >>> >>> ----- >>> Anna Lippel > -- >>