直接从 R 脚本读取 Excel 文件 [英] Read an Excel file directly from a R script

查看:29
本文介绍了直接从 R 脚本读取 Excel 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Excel 文件直接读入 R?或者我应该先将数据导出到文本文件或 CSV 文件,然后将该文件导入 R?

How can I read an Excel file directly into R? Or should I first export the data to a text- or CSV file and import that file into R?

推荐答案

是的.请参阅R wiki 上的相关页面.简短回答:gdata 包中的 read.xls 大部分时间都有效(尽管您需要在系统上安装 Perl——通常在 MacOS 和 Linux 上已经如此,但在 Windows 上需要一个额外的步骤,即参见 http://strawberryperl.com/).R wiki 页面上列出了各种警告和替代方案.

Yes. See the relevant page on the R wiki. Short answer: read.xls from the gdata package works most of the time (although you need to have Perl installed on your system -- usually already true on MacOS and Linux, but takes an extra step on Windows, i.e. see http://strawberryperl.com/). There are various caveats, and alternatives, listed on the R wiki page.

我认为不直接执行此操作的唯一原因是您可能想检查电子表格以查看它是否有故障(奇怪的标题、多个工作表 [您一次只能阅读一个,尽管您显然可以循环他们全部],包括情节等).但是对于包含纯数字和字符数据的格式良好的矩形电子表格(即,不是逗号格式的数字、日期、带有除零错误的公式、缺失值等......)我通常没有问题用这个过程.

The only reason I see not to do this directly is that you may want to examine the spreadsheet to see if it has glitches (weird headers, multiple worksheets [you can only read one at a time, although you can obviously loop over them all], included plots, etc.). But for a well-formed, rectangular spreadsheet with plain numbers and character data (i.e., not comma-formatted numbers, dates, formulas with divide-by-zero errors, missing values, etc. etc. ..) I generally have no problem with this process.

这篇关于直接从 R 脚本读取 Excel 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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