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

查看:161
本文介绍了直接从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上的相关页面。简单的答案: read.xls gdata 包大部分时间工作(尽管您需要安装Perl您的系统 - 通常在MacOS和Linux上都是真实的,但在Windows上需要额外的一步,例如 http://strawberryperl.com/ )。在R维基页面上列出了各种各样的注意事项和备选方案。

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天全站免登陆