J. Doe
J. Doe

Reputation: 1740

Is it possible to copy/paste R regression summary to Excel without using functions?

fit.iris.lm <- lm(Sepal.Length ~ Petal.Length + Petal.Width, iris)
summary(fit.iris.lm)

This gives us the following output:

enter image description here

I'm looking for a way to copy/paste the coefficients table from R console to Excel by highlighting the table and then Ctrl+C/Ctrl+V-ing it into Excel.

enter image description here

However, upon pasting it into Excel, all the columns are condensed into a single column:

enter image description here

I am looking for a way to copy/paste this output into Excel with all columns (Estimate, Std. Error) retained instead of condensed in one column and I am specifically looking for a way to do this without using any R functions for exporting tables (like write_xlsx) or any other similar functions - I just want to copy and paste it.

Upvotes: 4

Views: 2293

Answers (2)

G5W
G5W

Reputation: 37641

You could also just clean this up on the Excel side. After you paste it in Excel, select the pasted text. On the "Data" tab on the ribbon, select "Text to Columns".

Location of Text-to-Columns

This will open a dialog box. Leave it at "Fixed Width" and click "Next".

Dialog box

This should give you a preview of the way that it will divide the columns. For your example, it was fine so just click "Finish".

You get the result I think you want.

Final result

Upvotes: 3

lroha
lroha

Reputation: 34501

You can't avoid using any function but if you just want something you can neatly paste you can use broom::tidy() to convert the values into a tibble and clipr::write_clip() to copy it to the clipboard.

library(broom)
library(clipr)
library(magrittr)

lm(Sepal.Length ~ Petal.Length + Petal.Width, iris) %>%
  tidy() %>%
  write_clip()

Pasted into Excel:

enter image description here

Upvotes: 4

Related Questions