仅从 xls 读取某些列 [英] Read only certain columns from xls

查看:33
本文介绍了仅从 xls 读取某些列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多张工作表的 Excel 电子表格.格式如下:

I have an excel spreadsheet with several sheets. The format is as below:

Date        A       B       C       D       E       F                       Reference   Ref Date    Half life
03/01/13    6.29    5.28    8.15    4.93    11.67   6.4                     8.88        01/01/99    30.23
04/01/13    6.39    5.39    8.22    5.04    11.75   6.4                 
07/01/13    6.34    5.32    8.17    4.92    11.82   6.4                 
08/01/13    6.33    5.3 8.16    4.96    11.68   6.4                 
09/01/13    6.29    5.29    8.13    4.93    11.73   6.4                 
10/01/13    6.29    5.32    8.17    4.95    11.61   6.4                 
11/01/13    6.21    5.27    8.12    4.95    11.57   6.4                 
14/01/13    6.28    5.28    8.09    4.92    11.65   6.4                 
15/01/13    6.25    5.26    8.06    4.9 11.59   6.4                 
16/01/13    6.26    5.3 8.08    4.94    11.7    6.4                 
17/01/13    6.27    5.27    8.09    4.96    11.57   6.4                 
18/01/13    6.29    5.27    8.04    4.94    11.57   6.4                 
21/01/13    6.34    5.33    8.23    4.99    11.68   6.4                 
22/01/13    6.31    5.34    8.23    4.97    11.63   6.4                 
23/01/13    6.24    5.26    8.03    4.93    11.58   6.4                 
24/01/13    6.24    5.27    8.03    4.93    11.56   6.4                 
25/01/13    6.26    5.3 8.08    4.93    11.6    6.4 

我只想将列日期和 A-F 读入数据框中,而忽略 J1,2,K1,2 和 L,1,2 中用于计算某些值的元素.

I want to read the colmuns Date and A-F only into a data frame and ignore the elements in J1,2,K1,2 and L,1,2 which are used to calculate some values.

我正在使用 gdata 包中的 read.xls

I am using read.xls from the package gdata

read.xls("filename.xls", "sheetname", na.strings=c("NA","#DIV/0!"))

然而,这给了我一个包含列 A - L 的数据框.我可以将此数据框重新转换为所需的格式,但更愿意选择要读取的列.我可以使用 read.xls 以类似于 read.table 可以实现此目的的方式执行此操作吗 (如何仅将文件中的选择列读取到 R 中?(介于 `read.table` 和 `scan` 之间的一种快乐媒介?))

However this gives me a data frame containing columns A - L. I could recast this data frame to the desired format but would prefer to choose which columns to read. Can I do this with read.xls in a similar manner that read.table can achieve this (Ways to read only select columns from a file into R? (A happy medium between `read.table` and `scan`?))

推荐答案

您可以使用库 XLConnect 来读取 .xls 文件.函数 readWorksheet() 允许您设置需要导入的列和行.

You can use library XLConnect to read .xls files. Function readWorksheet() lets you set columns and rows you need to import.

library(XLConnect)
wb<-loadWorkbook("wb.xls")
data <- readWorksheet(wb, sheet = "Sheet1",startCol=1,endCol=7)

这篇关于仅从 xls 读取某些列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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