将R data.frame复制到Excel电子表格 [英] Copy an R data.frame to an Excel spreadsheet

查看:181
本文介绍了将R data.frame复制到Excel电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与这个,另一种替代方法是制作一个新功能,以通过 data.frame 复制到Excel剪贴板

  write.excel<-function(x,row.names = FALSE,col .names = TRUE,...){
write.table(x, clipboard,sep = \t,row.names = row.names,col.names = col.names .. 。)
}

write.excel(my.df)

最后是Excel中的Ctr + V:)


I have a question which is exactly similar to this question.

As part of my work, I have to copy output from the R Studio Console to an excel worksheet in order to make excel graphs. However, the R Studio Console uses formatted text, which excel doesn't read so well. To compensate, I'm always copying from the R Studio Console, pasting into notepad, then copying into Excel. That way, when I paste a table, I can tell excel that it's actually fixed width delimited data, and not just a clump of text.

How can I copy output from the R Studio console so that it goes into the clipboard as unformatted text so that I can paste it directly into Excel and thus organize the numbers into different cells? This would be very helpful as I dislike having to copy/paste tables into notepad then excel to make graphs.

解决方案

It works with an easy trick.

First, you have to visualize your data in the Viewer pane of Rstudio (you can use the function View()), then you should start selecting from the last value to the first, it is from bottom to top (see image). Note that the first cell should be selected completely. Finally, right click on the selection, copy, and then paste it in Excel as you want, with or without format.

Good luck!

UPDATE:

based on this Post, other alternative is making a new function to copy your data.frame to Excel through the clipboard:

write.excel <- function(x,row.names=FALSE,col.names=TRUE,...) {
  write.table(x,"clipboard",sep="\t",row.names=row.names,col.names=col.names,...)
}

write.excel(my.df)

and finally Ctr+V in Excel :)

这篇关于将R data.frame复制到Excel电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆