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

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

我只想将 colmuns Date 和 A-F 读入数据框中,并忽略 J1,2,K1,2 和 L,1,2 中用于计算某些值的元素。

我正在使用包 gdata 中的 read.xls
read.xls("filename.xls", "sheetname", na.strings=c("NA","#DIV/0!"))
然而,这给了我一个包含列 A - L 的数据框。我可以将此数据框重新转换为所需的格式,但更愿意选择要读取的列。我可以用 read.xls 以类似于 read.table 可以实现这一点的方式做到这一点( Ways to read only select columns from a file into R? (A happy medium between `read.table` and `scan`?) )

最佳答案

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

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

10-06 10:34
查看更多