【问题标题】:Reading specific columns and rows from excel sheet in R [closed]从R中的excel表中读取特定的列和行[关闭]
【发布时间】:2021-10-01 07:31:56
【问题描述】:

我有一个名为 Run.xlsx 的大型 xlsx 文件。这里面有多张纸,我想要一张叫做“因素”的纸。我还想从因子表中提取特定行 列,即 Z:AB 列和 15:71 行。

我尝试过使用 readxl 包,但它对我不起作用。

【问题讨论】:

  • data <- read_excel("Run.xlsx", sheet = "Factors") 后跟data=data[15:71,26:28] ?
  • 试试:library(xlsx) read.xlsx("yor_path\\your_file.xlsx", "sheet_name", rowIndex = 15:71 colIndex = your_index)

标签: r excel


【解决方案1】:

如果您的 Excel 文件列顺序可能发生变化,最好使用自动代码而不是选择列号。

你可以试试
1- 从“openxlsx”库中导入带有“read.xlsx”函数的 xlsx 文件
2- 选择具有特定名称的列

#1-import
library(openxlsx)
yourFile <- read.xlsx("yourPathway/yourFile.xlsx", sheet="yourSheet")

#2-columns selection
vectorNameColumns <- c("Age", "BMI", ..., "Gender")
vectorNameRows <- 15:71
refinedFile <- yourFile[vectorNameRows, vectorNameColumns]

如果您的 Excel 文件将被修改,或者如果您想将相同的代码应用于另一个 Excel文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多