简体   繁体   English

是否可以在不使用函数的情况下将 R 回归摘要复制/粘贴到 Excel 中?

[英]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:这给了我们以下 output:

在此处输入图像描述

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.我正在寻找一种将系数表从 R 控制台复制/粘贴到 Excel 的方法,方法是突出显示该表,然后将其 Ctrl+C/Ctrl+V-ing 到 ZC1D81AF5835844B4E9D936910D 中。

在此处输入图像描述

However, upon pasting it into Excel, all the columns are condensed into a single column:但是,将其粘贴到 Excel 后,所有列都被压缩为一列:

在此处输入图像描述

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. 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 (如write_xlsx)或任何其他类似功能 - 我只想复制和粘贴它。

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.您无法避免使用任何function 但如果您只是想要一些可以整齐粘贴的内容,则可以使用broom::tidy()将值转换为 tibble 和clipr::write_clip()将其复制到剪贴板。

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

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

Pasted into Excel:粘贴到 Excel 中:

在此处输入图像描述

You could also just clean this up on the Excel side.您也可以在 Excel 端进行清理。 After you paste it in Excel, select the pasted text.将其粘贴到 Excel、select 中后粘贴的文本。 On the "Data" tab on the ribbon, select "Text to Columns".在功能区的“数据”选项卡上,select“文本到列”。

文本到列的位置

This will open a dialog box.这将打开一个对话框。 Leave it at "Fixed Width" and click "Next".将其保留在“固定宽度”,然后单击“下一步”。

对话框

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.你得到我认为你想要的结果。

最后结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM