Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export R output to Excel

Tags:

r

excel

I like using R for statistical analysis but find it difficult to compare output of different models.

Is there any way, we can export output to excel to make it more readable (using some formatting like scientific to number notation, conditional formatting etc)?

As suggested by @42 How to Copy Summary() output from R to Excel, I tried capture.output() but it doesn't work properly. I've searched a lot, couldn't find a solution.

like image 297
Dr Nisha Arora Avatar asked Jun 21 '16 09:06

Dr Nisha Arora


Video Answer


2 Answers

Using the package XLConnect you can write R output to Excel files.

Here's an example, where I write a model and send the summary to excel:

library(XLConnect)
dat <- data.frame(rsp = rnorm(100, 0, 1), 
                  pred1 = rnorm(100, 0, 1), 
                  pred2 = rnorm(100, 0, 1))
model <- lm(rsp ~ pred1 + pred2, data = dat)
writeWorksheetToFile("model1.xlsx", 
                 data = summary(dat), 
                 sheet = "summary", 
                 header = TRUE,
                 clearSheets = TRUE)
like image 179
IJH Avatar answered Oct 26 '22 21:10

IJH


If you are trying to export the output of summary function, try this

write.csv(summary(data_frame),"output.csv")
like image 23
user2100721 Avatar answered Oct 26 '22 21:10

user2100721