将多个文件与不同的工作表名称组合到数据框架中
我正在尝试结合两个功能。
第一个函数可以读取和导入每个 *.xlsx文件中的单独文件夹
library(readxl)
library(tidyverse)
file.list <- list.files(pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)
,而第二个功能可以使用多个工作表工作表读取单个文件,并将A组合到一个数据框架中。
# set the working directory
setwd(path)
# accessing all the sheets
sheet = excel_sheets("Gfg.xlsx")
# applying sheet names to dataframe names
data_frame = lapply(setNames(sheet, sheet),
function(x) read_excel("Gfg.xlsx", sheet=x))
# attaching all dataframes together
data_frame = bind_rows(data_frame, .id="Sheet")
因此,任何人都可以帮助我如何在一个或多个中合并这两个功能,以在第一个功能中添加可能的可能性,以将表格名称应用于数据帧名称,然后在数据框架中附加在一起?
I am trying to combine two functions.
The first function can read and import each *.xlsx file into a separate folder
library(readxl)
library(tidyverse)
file.list <- list.files(pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)
While the second function can read the single file with multiple sheets worksheets and combine a into one data frame.
# set the working directory
setwd(path)
# accessing all the sheets
sheet = excel_sheets("Gfg.xlsx")
# applying sheet names to dataframe names
data_frame = lapply(setNames(sheet, sheet),
function(x) read_excel("Gfg.xlsx", sheet=x))
# attaching all dataframes together
data_frame = bind_rows(data_frame, .id="Sheet")
So, can anybody help me how to merge these two functions in one or more precisely to add possibility in the first function to applying sheet names to dataframe names and then to attaching together in data frame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要这个吗?
由
Do you need this?
Created on 2022-05-29 by the reprex package (v2.0.1)