【问题标题】:importing excel sheets in r but getting extra data frame inserted在 r 中导入 excel 工作表但插入了额外的数据框
【发布时间】:2020-03-16 02:15:32
【问题描述】:

我尝试使用此代码(使用 rio 包)将包含许多工作表的 excel 文件导入到 r:

   data_list <- import_list("x.xlsx")

效果很好,但是当我检查导入的纸张数量时,我发现了一张名为 RAW 的额外纸张

我怎样才能在没有得到这个额外的不需要的数据框的情况下导入工作表(它弄乱了我的所有数据)?谢谢你:)

【问题讨论】:

  • 全部导入后,做data_list &lt;- data_list[-1]
  • 谢谢 :) 我怎样才能将所有这些表绑定在一起?(没有得到这个额外的 RAw 数据框)因为当我使用这个代码时:import_list("x.xlsx", setclass= "tbl ", rbind = TRUE) 它再次添加这个 RAw 数据帧
  • 使用data.table::rbindlistdo.call(rbind, data_list)

标签: r excel dataframe import


【解决方案1】:

不知道为什么你会得到RAW,但我建议使用readxl-package 将excel文件读取到R。

library( readxl )

#get sheetnames of file
sheetnames <- readxl::excel_sheets( "./temp.xlsx" )
#loop over sheetname and read contenst, add to list
l <- lapply( sheetnames, function(x) readxl::read_excel( "./temp.xlsx", sheet = x ) )
#add sheetnames as names
names( l ) <- sheetnames

对于l的绑定,我建议data.table::rbindlist()。请确保根据您的需要设置 use.names-、fill- 和 idcol- 参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多