Is there some clever way of pasting results from R into Excel or Word, as tab limited format so they are easy to turn into a formatted table. Or is there some other way of doing this to avoid the time spent reformatting the output for presentation. If different, I am also interested in an answer to the same question but using S-Plus. Many thanks, Graham
graham.smith at myotis.co.uk (Graham M Smith) writes:> Is there some clever way of pasting results from R into Excel or Word, as > tab limited format so they are easy to turn into a formatted table.Have a look at write.table(). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Hi Graham, If you want it in excel I suggest you export it as a comma separated file, which can be done with something like:> data(airquality) > write.table(airquality, sep=",", row.names=FALSE, quote=FALSE, file="result.csv")This file will open nicely in excel. If you want it as tab separated use the same, but with 'sep="\t"'. Cheers, Anders. On Sun, 11 Apr 2004, Graham M Smith wrote:> Is there some clever way of pasting results from R into Excel or Word, as > tab limited format so they are easy to turn into a formatted table. > > Or is there some other way of doing this to avoid the time spent > reformatting the output for presentation. > > If different, I am also interested in an answer to the same question but > using S-Plus. > > Many thanks, > > Graham > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
Graham M Smith wrote:> Is there some clever way of pasting results from R into Excel or Word, as > tab limited format so they are easy to turn into a formatted table. > > Or is there some other way of doing this to avoid the time spent > reformatting the output for presentation.To copy/paste your data.frame X to Excel, use the following lines to write it to the clipboard from R: con <- file("clipboard", open="w") write.table(x, file=con, sep="\t", row.names=FALSE, col.names=FALSE) close(con) (you might want to define a wrapper function around it ...)> If different, I am also interested in an answer to the same question but > using S-Plus.What about copying from its spreadsheet? Uwe Ligges> Many thanks, > > Graham > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Anders, This seems a good start, and I will try it get it to work, on of the issues is that the results output is more complex than simply split by comma eg a typical Summary output of my current data set (below) However, I am a lot further forward than I was a few hours ago. Thanks Section Cave Season Year BatUse Black :225 ELE : 48 Autumn:101 1995 :217 0:233 Central:276 BRO : 47 Spring:169 1996 :149 1:450 Iron : 49 OCA : 46 Summer:101 1998 : 61 West :133 OGE : 46 Winter:312 1999 : 56 WAT : 46 1997 : 50 OCF1 : 45 1994 : 49 (Other):405 (Other):101 Number L.H. Min. : 0.0000 Min. : 0.0000 1st Qu.: 0.0000 1st Qu.: 0.0000 Median : 0.0000 Median : 0.0000 Mean : 0.9634 Mean : 0.9239 3rd Qu.: 1.0000 3rd Qu.: 1.0000 Max. :23.0000 Max. :23.0000
Graham M Smith <graham.smith <at> myotis.co.uk> writes: : Is there some clever way of pasting results from R into Excel or Word, as : tab limited format so they are easy to turn into a formatted table. Try this: data(iris) # get a test data frame require(R2HTML) HTML( iris, file("clipboard","w"), append=F ) Now go to Excel and press ctrl-V to paste it in. Once its in Excel you can copy and paste from there to Word.
Gabor Grothendieck <ggrothendieck <at> myway.com> writes:> > Graham M Smith <graham.smith <at> myotis.co.uk> writes: > > : Is there some clever way of pasting results from R into Excel or Word, as > : tab limited format so they are easy to turn into a formatted table. > > Try this: > > data(iris) # get a test data frame > require(R2HTML) > HTML( iris, file("clipboard","w"), append=F ) > > Now go to Excel and press ctrl-V to paste it in. > Once its in Excel you can copy and paste from there to Word.I noticed that your response to other respondents indicate that you want to display a summary. Try something like this with the above approach: HTML.matrix( summary(iris), file("clipboard", "w"), append=F ) # paste into Excel In Excel, with the table selected, you may wish to - set the cell width (Format | Column | Width) wider, say 12, and - right justify the matrix (click on right justify icon in toolbar)
Gabor,> > : Is there some clever way of pasting results from R into Excel or> > Try this: > > > > data(iris) # get a test data frame > > require(R2HTML) > > HTML( iris, file("clipboard","w"), append=F )This worked exactly as I was hoping. Many thanks, Graham
On Sun, 11 Apr 2004, Graham M Smith wrote:> Anders, > > This seems a good start, and I will try it get it to work, on of the > issues is that the results output is more complex than simply split by > comma eg a typical Summary output of my current data set (below)My current approach for model summaries is to use the xtable package and write things as HTML tables. -thomas> However, I am a lot further forward than I was a few hours ago. > > Thanks > > Section Cave Season Year BatUse > Black :225 ELE : 48 Autumn:101 1995 :217 0:233 > Central:276 BRO : 47 Spring:169 1996 :149 1:450 > Iron : 49 OCA : 46 Summer:101 1998 : 61 > West :133 OGE : 46 Winter:312 1999 : 56 > WAT : 46 1997 : 50 > OCF1 : 45 1994 : 49 > (Other):405 (Other):101 > Number L.H. > Min. : 0.0000 Min. : 0.0000 > 1st Qu.: 0.0000 1st Qu.: 0.0000 > Median : 0.0000 Median : 0.0000 > Mean : 0.9634 Mean : 0.9239 > 3rd Qu.: 1.0000 3rd Qu.: 1.0000 > Max. :23.0000 Max. :23.0000 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Thomas,> My current approach for model summaries is to use the xtable package and > write things as HTML tables.It was an HTML approach that Gabor suggested,using R2HTML, and that worked well, but I will try xtable as well. As always with R, there is a solution if you know where to look. Thanks for your help, Graham