Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

excel

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.

like image 655
J. Doe Avatar asked Aug 30 '25 17:08

J. Doe


1 Answers

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

like image 68
Ritchie Sacramento Avatar answered Sep 02 '25 06:09

Ritchie Sacramento