【问题标题】:error: reading specific rows and columns in .xlsx file in R错误:在 R 中读取 .xlsx 文件中的特定行和列
【发布时间】:2016-04-01 04:33:30
【问题描述】:

我必须在 R 中读取 .xlsx 文件中的特定行和列 我试过这个:

library(xlsx)
rm(list=ls())
getwd()
setwd("/Users/EmilyJiang/Desktop/duke_sem2/coursera/Getting and cleaning data/ps1-3")
colIndex <- 18:23
rowIndex <- 7:15
ps1Subset <- read.xlsx("getdata-data-DATA.gov_NGAP.xlsx", sheetIndex=1, 
                   colIndex=colIndex, rowIndex=rowIndex, header = TRUE)

但是有一个错误说:

strsplit(names(res), "\.") 中的错误:非字符参数

谁能给我一些建议?

【问题讨论】:

  • 您是否尝试过阅读不同的列、尝试过任何其他库或尝试阅读整个文件?一旦你在 R 中拥有所有内容,你总是可以丢弃列。我怀疑如果没有文件在手(不需要链接到它),将很难确定问题。您需要通过读取波形数据来确定问题。先尝试前几行。如果可行,请继续操作,直到该功能再次失效。检查有问题的行/列。解决问题并欢欣鼓舞。
  • 从错误来看,strsplit 使用的字符串分隔符可能不是一个而是 2 个字符:\. 是 2 个字符!

标签: r excel


【解决方案1】:

您的行与列混合在一起。将代码更改为:

rowIndex <- 18:23
colIndex <- 7:15

它应该可以工作

【讨论】:

    猜你喜欢
    • 2018-11-27
    • 2021-10-11
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 2020-07-07
    • 1970-01-01
    • 2014-03-03
    相关资源
    最近更新 更多